Subqueries vs joins

前端 未结 14 1993
闹比i
闹比i 2020-11-22 16:10

I refactored a slow section of an application we inherited from another company to use an inner join instead of a subquery like:

WHERE id IN (SELECT id FROM          


        
14条回答
  •  春和景丽
    2020-11-22 16:40

    Taken from the Reference Manual (14.2.10.11 Rewriting Subqueries as Joins):

    A LEFT [OUTER] JOIN can be faster than an equivalent subquery because the server might be able to optimize it better—a fact that is not specific to MySQL Server alone.

    So subqueries can be slower than LEFT [OUTER] JOINS.

提交回复
热议问题