我有以下疑问:
select *
from products as p
left join files as f on f.contentid = p.productid
where
p.state = 'active' AND
p.price > 0 order by p.created DESC
LIMIT 2200目前,对于2200行,此查询大约需要1.7秒。我不明白的是,为什么当我将限制从2200更改为10时,时间不会减少,更重要的是,我可以做些什么来加快速度?
发布于 2012-03-12 20:53:14
尝试:
EXPLAIN select *
from products p
left join files f on f.contentid = p.productid
where
p.state = 'active' AND
p.price > 0 order by p.created DESC
LIMIT 2200查看您需要哪些索引
发布于 2012-03-12 20:57:56
通过在files [contentid]和products [productid]上添加,它可以加快查询速度。
发布于 2012-03-12 20:58:37
通常,我只是尝试查询,看看什么能最大限度地减少运行时间。如果有必要,使用关系代数解决问题,并从中寻找需要优化的地方。这是我的建议:
SELECT *
FROM products as p, files f
WHERE f.contentid = p.productid
AND p.state = 'active'
AND p.price > 0
ORDER BY p.created DESC
LIMIT 2200https://stackoverflow.com/questions/9667337
复制相似问题