Hey, I was looking up some ways to make my MySQL queries more optimized, I bought some into practice but for some I wish to understand why they are recommended.
For example not using “LIMIT 10000,10” as I learned that MySQL reads 10010 rows, throws away the 10000 and returns the 10.
Now what I want to know is:
Referring to this article: http://forge.mysql.com/wiki/Top10SQLPerformanceTips
“Use a clever key and ORDER BY instead of MAX”
-
What is a “clever key” ?
-
What execution path does MySQL take to calculate MAX that it has been recommended to avoid it.
Thank you.
A clever key is a key that will allow the mysql to read the rows according to the wanted order, thus not using filesort or temporary tables for the sorting.
It does not have to be a primary key. To learn when you can use such a key for sorting read this very useful article: http://dev.mysql.com/doc/refman/5.0/en/order-by-optimization.html