SQL statement and performance combined query and federated classification query

Source: Internet
Author: User
Tags joins

Select    *from t1left join T2 on T2.sysno =t1. Asysnoleft join T3 on T3.sysno =t2. Asysnoleft join T4 on T4.sysno =t3. Asysnoleft join T5 on T5.sysno =t4. Asysnoleft join T6 on T6.sysno =t5. Asysnoleft join T7 on T7.sysno =t6. Asysnowhere t1.name like '%aaa% '

In the absence of any indexes, fuzzy queries, such SQL performance is the worst, such SQL for the Federated query SQL

Select    *from t1left join (   Select      * from   T2 left   joins T3 on T3.sysno =t2. Asysno left   joins T4 on T4.sysno =t3. Asysno) Vw_detail on  vw_detail. Sysno =t1. Asysnoleft Join (   Select      * from   T5 left   joins T6 on T6.sysno =t5. Asysno left   joins T7 on T7.sysno =t6. Asysno) vw_mm on vw_mm.sysno = t1. Ssysnowhere charindex (' AAA ', t1.name) >0

The SQL uses Left-join to classify a class of data, remove the like query, minimize the use of functions in the where, and then index the foreign keys of each table; this kind of SQL query is called Federated categorical query SQL. Generally query after this rule query should be very fast

The above SQL is for reference only

SQL statement and performance combined query and federated classification query

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.