http://www.cnblogs.com/Mainz/archive/2008/07/31/1257000.html

��������SQL Server Management Studio�牟�询�������: SELECT * FROM t1 WHERE 
c1=2; 

��������什么����菘���么去执�胁�询�模� -  知��然��知������然��

 

1.         Query Parsing, Synatax Error Check, and Authorization: Query 
Processer check the user is authorized to run the query;����询���������冉���
�法�������法��,�������权�����没�谢����权执����氐牟����������法����
�������?��

2.         Query Re-writing��Semantic Optimization�� ����询����������写SQL��
�并����应���呕�����

���:SELECT Emp.name, Emp.salary
                         FROM Emp, Dept
                            WHERE Emp.deptno = Dept.dno 

              Join�嵌���模���询����������写����并删���Dept��Join��

3.         Compile the SQL into internal query Plan; ������SQL���诓���询�苹�
��

       ��菘��选����训姆������������������全��扫�,����使������(pai
rs of key and location���������目录)����菘��冉����堑某杀������纬��诓�执��
�苹�����菘��诓��������选�����执�屑苹���������呕�����Optimizer����

4.         The query plan is handled by plan executor, which consists of 
many operators, e.g. joining, sorting, grouping... ����询�苹����苹�执����执��
���苹�执������芏�����撸�����执��Join, Sort, Group�龋���要�蟹��史���������
��������取��些���页������页������直�踊������校���些�谢������������... ...��


5.         Transaction manager is started as well to ensure the ACID of 
operations. �����������同时��������证原�硬����牟���一����, ���������������
��������������泄�������页���募����������������������志�������偷�也��执�校�
�����胁�询执����一�税�����小���

 

执��������:SELECT * FROM t1 WHERE c1=2�募虻ス�蹋�

 

1.        扫��t1�?����强�始��取��一����录������取��一����录�����������
���一����录����么���4����

2.        ����录�欠�����WHERE��������������3��������氐���1����

3.        �鸭�录�拥����

4.        ���亟���突��恕�

 

 

�����������呕������鼙冉�全��扫���������芫���执�屑苹�为扫��������
�������疲������1����桑�

扫������(Clustered or no-clustered)����位����录��

 

���:

 SELECT * FROM Customers WHERE contactID IN

(SELECT contactID FROM Contacts WHERE contactID=86) 

ORDER BY CustomerName DESC; 

 

���拥牟����校�

1.        �诒�[Contacts]��扫������位��录��

2.        �诒�[Customers]��扫������位��录��

3.        Hash match (inner join)����希匹�,���印�

4.        Sort������

 

�泄�Join

SQL Server employs three types of join operations: 

Nested loops joins 
Merge joins 
Hash joins 
 

���Join�������小������小��10�校�然�������Join����艽��������������希���N
ested loops joins�����摹���原��慰�Understanding Nested Loops Joins�� 
�������Join���都��小��������������������������扫�������������玫� 
scanning sorted indexes������Merge joins�����摹���原��慰�Understanding 
Merge Joins�� 
Hash joins������效�拇�������摹�没������摹�没����������。����愿��硬�询��
�屑��������效�������慰�Understanding Hash Joins�� 
 

��些只��一些�虻サ墓�蹋���实��菘��诓�执�泄�����当���拥摹���然���遣������
�开����员�����私������蔚�知识�潜���模��芄����������堑目�����应�谩���������
要知����么�茫�����要知��为什么������知��然��知������然�������一����菘���
���单结构图������趣���瞬慰���

 

http://images.cnblogs.com/cnblogs_com/mainz/DBMS.PNG 
--
��通���\魔����女����色�蕙����`���雪`��
����蕙����`���雪`���� 魔�h���榨����ルス�雪`����
魔��沙 ��������私? �������省�������巍���女������

�� ��源:����水思源 bbs.sjtu.edu.cn��[FROM: 207.46.55.28]