这个非常简单的查询花费了大量的时间:我可以优化此查询吗?
SELECT text, url, docid
FROM retrieve
LEFT JOIN citations2
ON citations2.fromdoc = retrieve.docid
WHERE citations2.todoc IS NULL
LIMIT 10;
它有一个左连接用NULL条件......会是事业?我到处都有索引。
这里是慢查询日志:
# Time: 130404 8:00:31
# [email protected]: em[em] @ zebra [130.239.162.142]
# Query_time: 27.006579 Lock_time: 0.000019 Rows_sent: 0 Rows_examined: 90682
use em_bg04;
SET timestamp=1365055231;
SELECT text, url, docid FROM retrieve LEFT JOIN citations2 ON citations2.fromdoc = retrieve.docid WHERE citations2.todoc IS NULL LIMIT 10;
这里是涉及的表的示意图,与尺寸一起(保持向下滚动以查看的EXPLAIN
输出为查询)
这里的EXPLAIN输出:
如此看来,它要经过整个表...当然。我读this,但我无法理解它。那么,有没有办法让这个查询更快?
尝试增加在'ON'子句where子句'选择文本,URL,docID的 FROM检索 LEFT JOIN citations2 ON citations2.todoc IS NULL AND citations2.fromdoc = retrieve.docid LIMIT 10;' – Meherzad 2013-04-04 09:26:03
@Meherzad现在好多了!谢谢(如果您将您的评论复制到答案我会接受) – dsign 2013-04-04 09:29:31