Which performs first WHERE clause or JOIN clause

前端 未结 5 1367
萌比男神i
萌比男神i 2021-02-01 18:47

Which clause performs first in a SELECT statement?

I have a doubt in select query on this basis.

consider the below example

         


        
5条回答
  •  盖世英雄少女心
    2021-02-01 19:18

    you can refer to this join optimization

    SELECT * FROM T1 INNER JOIN T2 ON P1(T1,T2)
                     INNER JOIN T3 ON P2(T2,T3)
      WHERE P(T1,T2,T3)
    

    The nested-loop join algorithm would execute this query in the following manner:

    FOR each row t1 in T1 {
      FOR each row t2 in T2 such that P1(t1,t2) {
        FOR each row t3 in T3 such that P2(t2,t3) {
          IF P(t1,t2,t3) {
             t:=t1||t2||t3; OUTPUT t;
          }
        }
      }
    }
    

提交回复
热议问题