The logic execution sequence of SQL queries, from the technical insider

Source: Internet
Author: User

-- The logic execution process of the query comes from the technical insider.
(8) Select (9) distinct (11) <top_specification> <select_list>
(1) From <left_table>
(3) <join_type> join <right_table>
(2) On <join_condition>
(4) Where <where_condition>
(5) group by <group_by_list>
(6) with {cube | rollup}
(7) having
(10) order by <order_by_list>

the standard SQL parsing sequence is: ( 1 ). from clause to assemble data from different data sources

( 2 ). where clause, used to filter records based on specified conditions

( 3 ). group by clause, divide data into multiple groups

( 4 ). use Aggregate functions for computing

( 5 ). use having filter Sub-Groups

( 6 ). calculate all expressions

( 7 ). use order by sort result sets

1. From: Run Cartesian product on the first two tables in the from clause to generate virtual table vt1
2. On: Apply the on filter to the vt1 table and insert VT2 only when the <join_condition> is true.
3. Outer (join): If you specify outer join to retain rows not found in the table (preserved table) as external rows, add them to VT2 to generate T3
If the from statement contains more than two tables, perform steps 1 and 3 again for the result table generated by the previous join and the next table.
4. Where: Apply the where filter to vt3 to insert vt4 only when the <where_condition> is true.
5. Group by: generates a vt5 instance by grouping the rows in vt4 by the column list in the group by clause.
6. cube | rollup: inserts supergroups into vt6 to generate vt6.
7. Having: Apply having filter to vt6. Only groups with
8. Select: process the select list to generate vt8
9. distinct: Remove duplicate rows from vt8 to generate vt9
10. Order by: sorts the rows of vt9 by the column list in the order by clause to generate a cursor VC10
11. Top: select a specified number or proportion of rows from the beginning of VC10 to generate vt11 and return to the caller

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.