user865238
user865238

Reputation: 43

mysql index optimization problem

I have a query like below.

SELECT 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?

Upvotes: 1

Views: 66

Answers (1)

Maxim Krizhanovsky
Maxim Krizhanovsky

Reputation: 26739

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

Upvotes: 1

Related Questions