First, brief
The MySQL statement is divided into 11 steps, as noted, the first execution is always the from operation, and finally the limit operation is performed. Each of these operations produces a virtual table that acts as a processing input , except that the virtual tables are transparent to the user, but only the last virtual table will be used as The result is returned. If you do not specify a clause in the statement, the corresponding step is skipped.
second, the specific analysis
- form: The Cartesian product is computed on the left table of the From and the table on the right. Generating a virtual table VT1
- on: The virtual table VT1 is filtered , only those rows that conform to <join-condition> are recorded in the virtual table VT2 .
- Join: If a outer join is specified (such as a LEFT JOIN or right join), rows that are not matched in the reserved table are added as outer rows to the virtual table VT2, resulting in a virtual table VT3, Rug If you have more than two tables in the FROM clause, you will repeat the steps for the result VT3 and the next table for the previous join join three steps until all the tables have been processed.
- where: The where condition is filtered on the virtual table VT3. Only records that match <where-condition> will be inserted into the virtual table VT4 .
- groupby: groups the records in VT4 according to the columns in the GROUP BY clause, producing VT5.
- CUBE | ROLLUP: A cube or ROLLUP operation is performed on the table VT5, resulting in a table VT6.
- Having: Apply a having filter to the virtual table VT6, only records that match virtual table VT7 .
- Select: Performs a select operation , selects the specified column, and inserts into the virtual table VT8 .
- DISTINCT: go to the record in the VT8. Generates virtual table VT9.
- Orderby: sorts the records in the virtual table VT9 by <order_by_list>, generating the virtual table VT10.
- LIMIT: Takes a record of the specified row , generates a virtual table VT11, and returns the result.
MySQL Statement execution order