What is ORDER BY NULL in MySQL?
Does it decrease the query speed?
It's for performance; adding ORDER BY NULL after a GROUP BY clause will make your query faster.
An explanation, from the manual:
By default, MySQL sorts all
GROUP BY col1, col2, ...queries as if you specifiedORDER BY col1, col2, ...in the query as well. If you include an explicitORDER BYclause that contains the same column list, MySQL optimizes it away without any speed penalty, although the sorting still occurs. If a query includesGROUP BYbut you want to avoid the overhead of sorting the result, you can suppress sorting by specifyingORDER BY NULL. For example:INSERT INTO foo SELECT a, COUNT(*) FROM bar GROUP BY a ORDER BY NULL;
This article describes the author successfully optimising a slow query by exploiting this trick, complete with the relevant parts of the EXPLAIN output.