according to MySQL documentation, adding ORDER BY NULL after GROUP BY should "avoid the overhead of sorting the result". If so, why is following query aprox 5 times slower\[code\]SELECT COUNT(*) advert_count, category.nameFROM advertLEFT JOIN category ON advert.category_id = category.category_idWHERE (advert.state_id = 2)GROUP BY advert.category_idORDER BY NULLLIMIT 5 \[/code\]than query with \[code\]ORDER BY advert_count\[/code\]?\[code\]SELECT COUNT(*) advert_count, category.nameFROM advertLEFT JOIN category ON advert.category_id = category.category_idWHERE (advert.state_id = 2)GROUP BY advert.category_idORDER BY advert_count DESCLIMIT 5 \[/code\]From phpMyAdmin profiling:
1st query:\[code\]Sorting for group -Sorting result 0.000002Sending data 12.069774\[/code\]2nd query:\[code\]Sorting for group 2.436986Sorting result 0.000028Sending data 0.000021\[/code\]I am confused by this, could anyone explain me what is going on there?
1st query:\[code\]Sorting for group -Sorting result 0.000002Sending data 12.069774\[/code\]2nd query:\[code\]Sorting for group 2.436986Sorting result 0.000028Sending data 0.000021\[/code\]I am confused by this, could anyone explain me what is going on there?