🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: cn.bbs.comp.database
Article #651

[MSSQL FAQ]Ƕ��ѭ�����ϲ����Ӻ͹�ϣ�����㷨

#651
From: Galaxy��VOLUNTEERS��Database
Date: Thu, 04 Dec 2008 11:07
76 lines
3675 bytes
Q������ʹ��"Set Statistics Profile On"���۲��ѯִ�мƻ�ʱ���ҷ��ֲ�ͬ�IJ�
ѯ��ʹ�ò�ͬ���������͡�����֮����ʲô���

A��
Microsoft SQL Server ʹ���ڴ��е�����͹�ϣ���Ӽ���ִ�����򡢽��������������
�Ȳ�����SQL Server �����������͵IJ�ѯ�ƻ�֧�ִ�ֱ�������ʱ��Ϊ���д洢����

SQL Server ʹ���������͵����Ӳ�����
Ƕ��ѭ��
�ϲ�����
��ϣ����

���ǵ��㷨���£�

Ƕ��ѭ��
�����������������뼯�е�ÿһ������ѯ�ڲ����뼯��ÿһ�С������д��Ϊ��
���������ڲ�����������ˡ�Ƕ��ѭ�����㷨�������£�

For each R1 in outer input set
    For each R2 in inner input set
        If R1 match with R2
            Output (R1, R2)

R1��R2�ֱ�Ϊ�����ڲ����뼯

�ϲ�����
�ϲ����ӻ��ڱȽ������Ѿ��������ڲ����뼯������С����Ϊ�������뼯�ĺ͡���
�����£�

Read first R1 at first input set
Read first R2 at second input set
While not reach the end of either of the inputs
begin
    if R1 match R2
    begin
        output (R1, R2)
        get next R2
    end
    else if R1 less than R2
        get next R1 
    else
        get next R2 
end

��ϣ����
��ϣ���ӻ�ͨ��Ƚ�����������Ĺ�ϣֵ�������֤��Ľ�����Ե�һ������
������һ����ϣ�?Ȼ������һ���Ĺ�ϣ����бȽϡ����ڴ�����OLTP���������
�ɲ�ϣ��õ��Ľ���㷨���£�

Create build table
For each R1
begin
    generate hash value of R1 join key
    insert into build table to appropriate hash bucket
end
for each R2
begin
    generate hash value of R2 join key
    for each R1 in corresponding hash bucket
        if match R1 and R2
            output (R1,R2)
end

����ϸ������μ�
"Understanding Hash 
Joins"<http://msdn.microsoft.com/en-us/library/ms189313.aspx>
"Understanding Merge 
Joins"<http://msdn.microsoft.com/en-us/library/aa178419.aspx>
"Understanding Nested Loops 
Joins"<http://msdn.microsoft.com/en-us/library/ms191318.aspx>�� 
--
Welcome to Database Board
��ӭ������ݿ��
http://bbs.sjtu.edu.cn/bbsdoc?board=database

�� ��Դ:����ˮ˼Դ bbs.sjtu.edu.cn��[FROM: 207.46.55.29]
Technical Details
Message-ID: <4dJIgN$byb@bbs.sjtu.edu.cn>
Path: arc1-ca.pugleaf.net!g2news2.google.com!news2.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!news.isoc.lu!news.shec6.edu.cn!SJTU

Show Full Headers
Complete Article Headers
X-Google-Thread: 101948,7fe2143a3fd03972,start
X-Google-Attributes: gid101948,domainid0,public,usenet
X-Google-Language: Chinese,GB
Path: arc1-ca.pugleaf.net!g2news2.google.com!news2.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!news.isoc.lu!news.shec6.edu.cn!SJTU
From: Dem.bbs@bbs.sjtu.edu.cn (Galaxy��VOLUNTEERS��Database)
Newsgroups: cn.bbs.comp.database
Subject: [MSSQL FAQ]Ƕ��ѭ�����ϲ����Ӻ͹�ϣ�����㷨
Date: 04 Dec 2008 11:07:42 GMT
Organization: ��ˮ˼Դ
Message-ID: <4dJIgN$byb@bbs.sjtu.edu.cn>
Mime-Version: 1.0
Content-Type: text/plain; charset="gb2312"
Content-Transfer-Encoding: 8bit
X-Filename: database/M.1228388855.A
Lines: 76