Applicable situations of nested loops, merge, and hash

Source: Internet
Author: User

1. Applicability of nested loop connections (nested loops)
Two tables: An External table and an internal table.

If the external input is very small and the internal input is very large and an index has been created in advance, nested loop join will be particularly efficient.

For which table is the outer table and the inner table during the connection, I found that SQL server will automatically arrange it for you, and it has nothing to do with the position you write, it automatically selects a table with a small amount of data as an outer table, and a table with a large amount of data as an inner table.

2. Merge join (merge)
It means that both tables have indexes in the on filter conditions and are ordered. In this way, SQL server uses merge join for join, which improves performance.

If an index exists and no index exists, the nested loops join is selected.
 

3. Hash join)
If neither of the two tables has an index in the on filter condition, hash join is used.

That is, use Hash joinAlgorithmIt is due to the lack of ready-made indexes.

References:

Inside SQL Server 2008 T-SQL.

Advanced query optimization concepts
Http://msdn.microsoft.com/zh-cn/library/ms191426 (V = SQL .100). aspx

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.