Mysql query with Left Join is too very slow

后端 未结 6 1170
萌比男神i
萌比男神i 2021-02-13 16:09

Query:

   select `r`.`id` as `id` 
     from `tbl_rls` as `r` 
left join `tblc_comment_manager` as `cm` on `cm`.`rlsc_id` != `r`.`id`

Both tabl

6条回答
  •  一向
    一向 (楼主)
    2021-02-13 16:29

    You may need to provide more info. But one thing I would try is reversing the order of your ON clause (because it's so easy):

    ON r.id != cm.rlsc_id

    Edit: and you should put indexes on your PK (id) columns.

    But I think this article might help you out.

    Basically it says that NOT IN takes less resources than LEFT JOIN. A commenter in that article mentions using NOT EXISTS is best.

    Also, I'm not sure this is accurate or not, but this article says that NOT IN does a full table scan, and NOT EXISTS can use an index.

提交回复
热议问题