Detailed execution order of MySQL statements

 

The MySQL statement is divided into 11 steps. As marked in the figure below, the first operation is always the FROM operation, and the last is the LIMIT operation. Each of these operations will produce a virtual table. This virtual table is used as a processing input, but these virtual tables are transparent to the user, but only the last virtual table will be returned as the result. If no clause is specified in the statement, the corresponding steps will be skipped

 

Let's analyze each stage of query processing specifically.
1. FORM: Calculate the Cartesian product of the left table and the right table of FROM. Generate virtual table VT1
2. ON: ON filter for virtual table VT1, only those rows that meet <join-condition> will be recorded
in virtual table VT2.
3. JOIN: If OUTER JOIN (such as left join, right join) is specified, the unmatched rows in the reserved table will be added as external rows to the virtual table VT2, resulting in the virtual table VT3, rug from clause contains two If there are more than one table, then the three steps of steps 1 to 3 will be repeated for the result VT3 of the previous join connection and the next table, until all the tables are processed.
4. WHERE: Perform WHERE condition filtering on the virtual table VT3. Only records that match <where-condition> will be inserted into the virtual table VT4.
5. GROUP BY: Group the records in VT4 according to the columns in the group by clause to generate VT5.
6. CUBE | ROLLUP: Perform the cube or rollup operation on table VT5 to generate table VT6.
7. HAVING: Yes Virtual table VT6 has filtering applied, and only records that match <having-condition> will be inserted into virtual table VT7. 

Published 568 original articles · Like 180 · Visits 180,000+

Guess you like

Origin blog.csdn.net/Delicious_Life/article/details/105616621