使用Left Join的MySQL查询太慢 [英] Mysql query with Left Join is too very slow
本文介绍了使用Left Join的MySQL查询太慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
查询:
select `r`.`id` as `id`
from `tbl_rls` as `r`
left join `tblc_comment_manager` as `cm` on `cm`.`rlsc_id` != `r`.`id`
两个表都有8k条记录,但是为什么它却很慢,需要2-3分钟,有时还要花更多时间?
Both tables have 8k records but why is it very slow, taking 2-3 minutes and more sometimes?
OMG,此查询使mysql服务器停机.很快就会回复你们人民:(
OMG , this query makes mysql server down. Will get back to you peoples in a second :(
所有建议对这些索引编制索引的人都是正确的. 是的,我写的查询很傻而且有错误.感谢纠正我.
All peoples those suggested Indexing the columns are all Correct. Yeh the query i wrote was silly and buggy. Thanks correcting me.
推荐答案
还考虑为您的表建立索引.我们正在100万以上的记录表上运行多个左联接,这些联接不需要一两秒钟就能返回结果.
Consider also indexing your tables. We're running multiple left joins on a 1million+ record table that doesn't take more than a second or two to return results.
这篇关于使用Left Join的MySQL查询太慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文