Subqueries vs joins

前端 未结 14 1876
闹比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:59

    A "correlated subquery" (i.e., one in which the where condition depends on values obtained from the rows of the containing query) will execute once for each row. A non-correlated subquery (one in which the where condition is independent of the containing query) will execute once at the beginning. The SQL engine makes this distinction automatically.

    But, yeah, explain-plan will give you the dirty details.

    0 讨论(0)
  • 2020-11-22 17:00

    Optimizer didn't do a very good job. Usually they can be transformed without any difference and the optimizer can do this.

    0 讨论(0)
提交回复
热议问题