Removal of implicit and explicit sorting for GROUP BY
In MySQL, historically GROUP BY was used to provide sorting as well. If a query specified GROUP BY, the result was sorted as if ORDER BY was present in the query.
mysql-5.7> CREATE TABLE t (id INTEGER, cnt INTEGER); Query OK, 0 rows affected (0.03 sec) mysql-5.7> INSERT INTO t VALUES (4,1),(3,2),(1,4),(2,2),(1,1),(1,5),(2,6),(2,1),(1,3),(3,4),(4,5),(3,6); Query OK, 12 rows affected (0.02 sec) Records: 12 Duplicates: 0 Warnings: 0 mysql-5.7> SELECT id, SUM(cnt) FROM t GROUP BY id; +------+----------+ | id | SUM(cnt) | +------+----------+ | 1 | 13 | | 2 | 9 | | 3 | 12 | | 4 | 6 | +------+----------+ 4 rows in set (0.00 sec)
MySQL here implicitly sorts the results from GROUP BY (i.e.…
Source: Removal of implicit and explicit sorting for GROUP BY
Leave a Reply