麻烦大家以实例讲下SQL Server中Merge Join与Hash Join(hash match)的区别,谢谢!

解决方案 »

  1.   

    这个我也不知道要怎么解释:
    1.Merge Join
    2.Hash Join
      

  2.   

    概念性的问题查一下msdn就有了
      

  3.   

    很简单,算法不同。
    merge join :
    get first row R1 from input 1
    get first row R2 from input 2
    while not at the end of either input
       begin
          if R1 joins with R2
             begin
                output (R1, R2)
                get next row R2 from input 2
             end
          else if R1 < R2
             get next row R1 from input 1
          else
             get next row R2 from input 2
       endHash join :
    for each row R1 in the build table
       begin
          calculate hash value on R1 join key(s)
          insert R1 into the appropriate hash bucket
       end
    for each row R2 in the probe table
       begin
          calculate hash value on R2 join key(s)
          for each row R1 in the corresponding hash bucket
             if R1 joins with R2
                output (R1, R2)
       endreferences:
    Inside Microsoft SQL Server 2005 Query Tuning and Optimization
    Hash joins and hash teams in Microsoft SQL Server
    http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.114.3183&rep=rep1&type=pdf
      

  4.   

    Merge Join是用于中型表,Hash Join是用于大型表吗?
      

  5.   

    hash “主要”用在没有索引、没有排序的大表关联,并且在内存中排序。Merge的特点是已排序或者对已排序的的表进行关联。