Logical query-processing phases

Logical query-processing phases in brief

 

 

 

(1) FROM 

This phase identifies the query’s source tables and processes table operators.
Each table operator applies a series of subphases.
For example, the phases involved in a join are
(1-J1) Cartesian Product, (1-J2) ON Predicate, (1-J3) Add Outer Rows.
This phase generates virtual table VT1.

(1-J1) Cartesian Product 

This phase performs a Cartesian product (cross join) 
between the two tables involved in the table operator, generating VT1-J1.

(1-J1) Cartesian Product This

This phase filters the rows from VT1-J1 based on the predicate
that appears in the ON clause (<on_predicate>).
Only rows for which the predicate evaluates to TRUE are inserted into VT1-J2.

(1-J3) Add Outer Rows

 If OUTER JOIN is specified (as opposed to CROSS JOIN or INNER JOIN), 
rows from the preserved table or tables for which a match was not found 
are added to the rows from VT1-J2 as outer rows, generating VT1-J3. 

(2) WHERE

 This phase filters the rows from VT1 based on the predicate that appears in the WHERE clause (<where_predicate>). 
Only rows for which the predicate evaluates to TRUE are inserted into VT2.

(3) GROUP BY

This phase arranges the rows from VT2 in groups based on the set of expressions 
(aka, grouping set) specified in the GROUP BY clause, generating VT3. Ultimately, 
there will be one result row per qualifying group. 

(4) HAVING

This phase filters the groups from VT3 based on the predicate that 
appears in the HAVING clause (<having_predicate>). Only groups for 
which the predicate evaluates to TRUE are inserted into VT4. 

(5) SELECT

This phase processes the elements in the SELECT clause, generating VT5.

(5-1) Evaluate Expressions

This phase evaluates the expressions in the SELECT list, generating VT5-1.

(5-2) DISTINCT

This phase removes duplicate rows from VT5-1, generating VT5-2.

(6) ORDER BY

 This phase orders the rows from VT5-2 according to the list specified in the ORDER BY clause, 
generating the cursor VC6. Absent an ORDER BY clause, VT5-2 becomes VT6. 

(7) TOP | OFFSET-FETCH

 This phase filters rows from VC6 or VT6 based on the top or offset-fetch specification, 
generating VC7 or VT7, respectively. With TOP, this phase filters the specified 
number of rows based on the ordering in the ORDER BY clause, or based on arbitrary order 
if an ORDER BY clause is absent. With OFFSET-FETCH, this phase skips the specified number of rows, 
and then filters the next specified number of rows, based on the ordering in the ORDER BY clause. 
The OFFSET-FETCH filter was introduced in SQL Server 2012. 

to be end

 

posted @ 2016-07-21 15:07  Jeffrey Chan  阅读(361)  评论(0编辑  收藏  举报