I have a query like below.
SE开发者_如何学PythonLECT a,b,c,d
FROM table_name
WHERE e=1 AND f=0
GROUP BY d
ORDER BY id DESC LIMIT 5
when I indexed (e,f,d) query time : 4 sec.
when I indexed (d,e,f) query time : 20 sec.
So that I understand that index colums ordering is important. Which index would be better for mysql?
Indexes should first satisfy the where clause, then the group or order clause. Always use EXPLAIN
on your query to see how it is performed
精彩评论