MySQL statement execution sequence and MySQL statement execution sequence

Source: Internet
Author: User

MySQL statement execution sequence and MySQL statement execution sequence

MySQL statements are divided into 11 steps. As marked, the first FROM operation is always executed, and the last LIMIT operation is executed. Each operation generates a virtual table, which serves as a processing input, but these virtual tables are transparent to users, however, only the last virtual table is returned as a result. If a clause is not specified in a statement, the corresponding steps are skipped.

Next, we will analyze each stage of query processing.
  1. FORM: Calculates the Cartesian product for the table on the left and the table on the right of FROM. Generate virtual table VT1
  2. ON: Virtual table VT1 is filtered ON. Only the rows that match <join-condition> are recorded in virtual table VT2.
  3. JOIN: If outer join (such as left join and right join) is specified, the unmatched rows in the table are retained and added as external rows to VT2, resulting in virtual table VT3, if the rug from clause contains more than two tables, the result VT3 generated by the previous join and the next table are repeatedly executed in step 1 ~ 3. The three steps are completed until all the tables are processed.
  4. WHERE: Perform WHERE filter on the virtual table VT3. Only records that match <where-condition> are inserted into the virtual table VT4.
  5. GROUP: Groups records in VT4 Based on the columns in the group by clause to generate VT5.
  6. CUBE | ROLLUP: Perform cube or rollup operations on table VT5 to generate table VT6.
  7. HAVING: Apply having filtering to the virtual table VT6. Only records that meet
  8. SELECT: Execute the select Operation, select the specified column, and insert it to the virtual table VT8.
  9. DISTINCT: Deduplicates records in VT8. Generate virtual table VT9.
  10. ORDER: Sort the records in virtual table VT9 by <order_by_list> to generate virtual table VT10.
  11. LIMIT: Retrieves records of the specified row, generates the virtual table VT11, and returns the result.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.