Introduction to the Logical query processing phase
From : performs a cartesian product (Cartesian product) (cross join) on the first two tables in the FROM clause, generating a virtual table VT1
On : apply an on filter to VT1. Only those rows that make it true are inserted into the VT2.
OUTER (Join): If OUTER join is specified (relative to cross join or (INNER join), the reserved table (preserved table: Left outer join marks the left table as a reserved table, right outer join marks the right table as a reserved table, A full outer join that marks two tables as a reserved table) does not find a matching row to be added to VT2 as an outer row, generating VT3. If the FROM clause contains more than two tables, repeat steps 1 through 3 for the result table and the next table that were generated for the previous join until all the tables have been processed.
Where: apply a where filter to VT3. Only the line that is true is inserted into the VT4.
GROUP By: groups the rows in VT4 by the list of columns in the GROUP BY clause, generating VT5.
cube| ROLLUP: Inserts a Hyper-group (suppergroups) into VT5, generating VT6.
Having : apply a having filter to VT6. Only groups that are true are inserted into the VT7.
Select: processes the select list, producing VT8.
DISTINCT: removes duplicate rows from VT8, resulting in VT9.
ORDER BY: generates a cursor (VC10) by sorting the rows in VT9 by the list of columns in the ORDER by clause.
TOP: selects the specified number or scale of rows from the beginning of the VC10, generates the table VT11, and returns the caller.
Note: Step 10, sort the rows returned by the column list in the ORDER BY clause, and return the cursor VC10. This step is the first and only step you can use the column aliases in the select list. This step differs from the other step in that it does not return a valid table, but instead returns a cursor. SQL is based on the set theory. The collection does not pre-order its rows, it is only a logical collection of members, and the order of the members is irrelevant. A query that sorts a table can return an object that contains rows organized in a specific physical order. ANSI calls this object a cursor. Understanding this step is the basis for a proper understanding of SQL.
Original address: http://bbs.delit.cn/thread-171-1-1.html
Reprint please specify the source:
Author: metric Technology http://www.delit.cn
Introduction to SQL Server logical query processing phase