SQL Server 2005 Merge Join algorithm

Source: Internet
Author: User
Tags hash join joins

Brief introduction:

If two join inputs are not small but are sorted on the joined columns (for example, if they are obtained by scanning a sorted index), the merge join is the fastest join operation. If two join inputs are large and the size of the two inputs is similar, the predefined merge joins provide a similar performance to the hash join.

From our analysis last time, nested loops are good for both input and output, so if the input and input are large, the combination algorithm is optimal.

Best use:

Merging the joins itself is fast, but selecting a merge join can be time-consuming if you need a sort operation. However, if the data is large and can be obtained from an existing B-tree index, the merged join is usually the fastest available join algorithm.

Let's test the best case for a merged connection:

Test environment: Table: Workflowinfo1 about 450,000 table workflowbase1 about 45,000 articles

Condition: Workflowbase1 The column id,creater are indexed, and WorkflowId in Workflowinfo1 is indexed.

If two join inputs are not small but are sorted on the joined columns (for example, if they are obtained by scanning a sorted index), the merge join is the fastest join operation. If two join inputs are large and the size of the two inputs is similar, the predefined merge joins provide a similar performance to the hash join. ~: (creater=4028814110830a1e01108fe379e60061 ' WORKFLOWBASE1 table has 1023 data)

Test statement:

Merging algorithms

select a.* from workflowbase1 a inner merge join dbo.workflowinfo1 b
on a.id=b.workflowid and a.creater='4028814110830a1e01108fe379e60061'

Hash algorithm

select a.* from workflowbase1 a inner hash join dbo.workflowinfo1 b
on a.id=b.workflowid and a.creater='4028814110830a1e01108fe379e60061'

Note: This two SQL differs from the previous nested loop example, a SELECT * and one is a select a.*

Restart the database service to view costs:

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.