nested query vs jOINs

前端 未结 4 357
醉话见心
醉话见心 2021-01-12 14:08

whos could be much efficient if I use nestted subquery, JOINs Or maybe temp tables .. another question : in subqueries if i use IN Cl

4条回答
  •  有刺的猬
    2021-01-12 14:30

    The two queries are equivalent, and should produce identical plans. It's a misconception that CTEs are compiled only once, providing a performance benefit. Non-recursive CTEs are just syntactic sugar for derived tables/inline views (IMO mistakenly referred to as subqueries).

    Secondly, JOINs vs IN/EXISTS can produce different results. JOINs risk duplicated data, if there's two or more supporting records. EXISTS is best used if there are duplicate criteria, because it returns true on the first encounter of the criteria - making it potentially faster than IN or JOIN. There's no data duplication risk when using EXISTS or IN.

提交回复
热议问题