Re: Slow query. Why is it slow?
Rick James Wrote:
-------------------------------------------------------
> sql.html is nice. What did you use to format it?
Hi Rick;
Thank you for your post. I use
http://www.dpriver.com/pp/sqlformat.htm to format sql. And for explain boxes I just copy paste the code for the table :)
Rick I have go t another question for you:
Query # 7 takes 0.0020 seconds; Its here:
http://webmoosh.com/sql.html#q7
Query# 9 on the other hand takes 5.5042 sec
http://webmoosh.com/sql.html#q9
Why in query 7 Mysql chooses PRIMARY and in query 9 it uses category_index (and the query 9 is slow)? If you look at indexes you see that category_index and class_index both have exact cardinality of 17!
What should I do so I can use exact same query for both cases? Drop category_index? Now I found out that I can FORCE INDEX (PRIMARY) and that way the query takes 0.0003 seconds but that's not right!
Indexes:
http://webmoosh.com/indexes.png
Thanks Rick