MySQL - SELECT WHERE field IN (subquery) - Extremely slow why?

前端 未结 10 2162
情书的邮戳
情书的邮戳 2020-11-27 10:06

I\'ve got a couple of duplicates in a database that I want to inspect, so what I did to see which are duplicates, I did this:

SELECT relevant_field
FROM some         


        
10条回答
  •  -上瘾入骨i
    2020-11-27 10:31

    sometimes when data grow bigger mysql WHERE IN's could be pretty slow because of query optimization. Try using STRAIGHT_JOIN to tell mysql to execute query as is, e.g.

    SELECT STRAIGHT_JOIN table.field FROM table WHERE table.id IN (...)
    

    but beware: in most cases mysql optimizer works pretty well, so I would recommend to use it only when you have this kind of problem

提交回复
热议问题