I have problem with query.
Query: http://pastebin.com/RNW0vgJX Products: 10 000 Time: ~18s
How I Can optymalize this query?
Like Mark Baker suggested, do an explain on the query it helps out a lot to see where indexes might be forgotten.
In basic every primary and foreign key should have one.
Also distinct products
.* is probably very expensive. You could rewrite the query like
select * from `products` where productid in (your first query ).
This is usually a lot faster than a distinct on a all columns of a table.
explain results: In the explain the foreign key indexes are looking good. there is some delay in the grouping and sorting:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.