使用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.