In the interview to do the topic, but not quite sure, later read the following this blog, feel that said is very clear, so excerpt here: Address: http://www.cnblogs.com/rollenholt/p/3776923.html
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 processing
- Form : Calculates the Cartesian product for the table to the left of the From and the table on the right. Generates a virtual table VT1
- on : VT1 The virtual table is on, 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 : where conditional filtering is performed on the virtual table VT3. Only records that match <where-condition> will be inserted into the virtual table VT4.
- GROUP by : Groups the records in VT4 according to the columns in the GROUP BY clause, producing VT5.
- CUBE | ROLLUP : VT5 The table with a cube or ROLLUP operation, resulting in a table VT6.
- Having : Apply a have filter to a virtual table VT6, only records that match
- Select : Performs a select operation, selects the specified column, and inserts it into the virtual table VT8.
- DISTINCT : de-weight the records in VT8. 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.
Internal execution order of MySQL statements