Explicitly Disable Sorting of Result Set
Copyright © 2024 PawSQL
Problem Definition
In earlier versions of MySQL, GROUP BY would default to sorting by the grouping fields even without an ORDER BY clause. This could cause unnecessary file sorting which impacts SQL query performance. Adding ORDER BY NULL forces disabling sorting on the result set.
For example in the following:
SELECT l_orderkey, sum(l_quantity)
FROM lineitem
GROUP BY l_orderkey;
