sql server query execution order

Note: The most obvious feature that sets SQL Server apart from other programming oracles is the order in which code is processed.

 

Each step produces a virtual table that is used as input for the next step. These virtual tables are not available to callers (client applications or external queries). Only the table generated in the last step will be returned to the caller. If a clause is not specified in the query, the corresponding step will be skipped.

     1" FROM: Perform a Cartesian product (cross join) on the first two tables in the from clause to generate a virtual table VT1;

     2>ON: Apply the on filter to VT1. Only those rows that make the ON filter true are inserted into VT2;

     3" OUTER (JOIN): If OUTER JOIN (relative to CROSS JOIN or INNER JOIN) is specified, the row that does not find a match in the reserved table will be added to VT2 as an external row to generate VT3; if the FROM clause contains more than two tables , then repeat steps 1 to 3 for the result table generated by the previous join and the next table; only until all tables are processed;

    4" WHERE: Apply the WHERE filter to VT3, and only the rows that make the WHERE filter condition TRUE are inserted into VT4;

    5" GROUP BY: Group the rows in VT according to the column list in the group by clause to generate VT5;

    6"CUBE|ROLLUP: Insert the supergroup into VT5 to generate VT6;

    7" HAVING: Apply the having filter to VT6, and only groups that make the condition TRUE are inserted into VT7;

    8"SELECT: process the select list and generate VT8;

    9" DISTINCT: Remove duplicate lines from VT8 to generate VT9;

    10" ORDER BY: Sort the rows in VT9 according to the column list in the order by clause to generate a cursor (VC10);

    11"TOP: Select the specified number or proportion of rows from the beginning of VC10, generate table VT11, and return it to the caller.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325382838&siteId=291194637