[英]Mysql Query FROM SLOW LOG
I have problem with query.我有查询问题。
Query: http://pastebin.com/RNW0vgJX Products: 10 000 Time: ~18s查询: http : //pastebin.com/RNW0vgJX产品:10 000 时间:~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.就像 Mark Baker 建议的那样,对查询做一个解释,它有助于找出索引可能被遗忘的地方。
In basic every primary and foreign key should have one.基本上每个主键和外键都应该有一个。
Also distinct products
.* is probably very expensive.同样不同的
products
.* 可能非常昂贵。 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:
分组和排序有一些延迟:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.