MySQL Statement execution order
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 is returned as a result. If you do not specify a clause in the statement, the corresponding step is skipped.
let's take a concrete look at each phase of query processing1. FORM:calculates the Cartesian product on the left table of the From and the table on the right. Generating a virtual table VT12. On: The virtual table VT1 on the filter, only those in accordance with <Join-condition>rows are recorded in the virtual table VT2. 3.JOIN: If the outer is specifiedJOIN(such as LeftJoin, rightJoin), the rows that are not matched in the reserved table are added as outer rows to the virtual table VT2, the virtual table VT3 is generated, and the rug FROM clause contains more than two tables, then the results of the previous join connection VT3 and the next table are repeated steps 1~3 These three steps until all the tables have been processed. 4. Where: the Where condition is filtered on the virtual table VT3. Only in accordance with <where-condition>will be inserted into the virtual table VT4. 5. GROUP BY: Groups the records in the VT4 according to the columns in the GROUP BY clause, producing VT5. 6. CUBE | ROLLUP: A cube or ROLLUP operation is performed on the table VT5, resulting in a table VT6. 7. Having: The use of the virtual table VT6 have filtering, only in line with will be inserted into the virtual table VT7. 8.Select : Performs a select operation, selects the specified column, and inserts into the virtual table VT8. 9. DISTINCT: The VT8 in the record to go to weight. Generates virtual table VT9. ORDER BY: Sorts the records in the virtual table VT9 by <order_by_list> to produce 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