Logical query processing steps for the execution of the SELECT statement:
| Execution order |
Statement |
| 8 |
SELECT |
| 9 |
DISTINCT |
| 11 |
<TOP_specification> <select_list> |
| 1 |
From <left_table> |
| 3 |
<join_type> Join <right_table> |
| 2 |
On <join_condition> |
| 4 |
WHERE <where_condition> |
| 5 |
GROUP by<group_by_list> |
| 6 |
with {CUBE | ROLLUP} |
| 7 |
Having |
| 10 |
ORDER by <order_by_list> |
Note:
1,from: Performs a Cartesian product on the first two tables in the FROM clause, generating a virtual table VT1;
2,on: Apply an on filter to the VT1. Only those that make <join_condition> true are inserted into the VT2;
3,outer (Join): If OUTER join is specified, no matching rows in the reserved table are added to VT2 as outer rows, VT3 is generated, and 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 tables have been processed;
4, apply the where filter to the VT3. Only lines that make <where_condition> true are inserted into the VT4;
5,group by: Groups The rows in the VT4 according to the list in the GROUP BY clause, generating VT5;
6,cube | ROLLUP: Inserting the super-group into the VT5 to generate VT6;
7,having: Has a having filter applied to the VT6. Only groups that make
8,select: Process SELECT list, generate VT8;
9,distinct: Remove duplicate rows from VT8, resulting in VT9;
10,order by: The rows in the VT9 are sorted by the list in the ORDER by clause, generating the table VT10;
11,top: Selects the specified number or scale of rows from the beginning of the VT10, generates the table VT11, and returns it to the caller.
Order of execution of SELECT statements in SQL statements