Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

¸ßЧSQL²éѯ֮Ë÷Òý£¨II£©

ÉÏ»ØÎÒÃÇ˵µ½ÆÀ¹ÀÒ»ÌõÓï¾äÖ´ÐÐЧÂÊÖ÷Òª¿´Âß¼­ IO £¨É¶ÊÇÂß¼­ IO £¬É¶ÊÇÎïÀí IO ¼ûÁª»úÎĵµ£©£¬Õâ´ÎÎÒÃǼÌÐø¡£
ÎÒÃÇÏÈ˵˵£¬·µ»Ø¶àÐнá¹ûʱ£¬ÎªÊ²Ã´ SQLServer ÓÐʱ»áÑ¡Ôñ index seek £¬ÓÐʱ»áÑ¡Ôñ index scan ¡£
ÒÔ nonclustered index ΪÀý˵Ã÷¡£
ÏñËùÓеÄË÷Òý B Ê÷Ò»Ñù£¬·Ç¾Û¼¯Ë÷ÒýÊ÷Ò²°üÀ¨ÍêÈ«ÓÉË÷ÒýÊý¾Ý×é³ÉµÄ¸ù½ÚµãºÍÖм伶½Úµã£»µ«ÊǺ;ۼ¯Ë÷ÒýÊ÷²»Í¬µÄÊÇ£¬¾Û¼¯Ë÷ÒýÊ÷Ò¶½Úµã°üº¬µÄÊÇ»ù´¡±íµÄÊý¾ÝÒ³£¨ÎÒÃdz£Ëµ£¬±íµÄÎïÀí´æ´¢Ë³ÐòºÍ¾Û¼¯Ë÷ÒýÏàͬ£¬¾ÍÊÇÕâ¸öÔ­Òò£©,·Ç¾Û¼¯Ë÷ÒýÊ÷Ò¶½ÚµãÊÇË÷ÒýÒ³¡£ SQLServer ͨ¹ý·Ç¾Û¼¯Ë÷Òý²éÕÒÊý¾Ýʱ£¬»áͨ¹ýÕâ¸ö·Ç¾Û¼¯Ë÷Òý¼üֵȥËÑË÷¾Û¼¯Ë÷Òý£¬½ø¶ø¼ìË÷»ù´¡±íÊý¾ÝÐС£
¼ÙÉèÓÐÕâÑùÒ»ÕÅ±í£¬·Ç¾Û¼¯Ë÷ÒýÊ÷Éî¶ÈΪ 2 £¬Ò»²ã¸ù½Úµã£¨ 1 ¸öË÷ÒýÒ³£©£¬Ò»²ãÒ¶½Úµã£¨ 4 ¸öË÷ÒýÒ³£©¡£¾Û¼¯Ë÷ÒýÊ÷Éî¶ÈΪ 3 £¬Ò»²ã¸ù½Úµã£¨ 1 ¸öË÷ÒýÒ³£©£¬Ò»²ãÖм伶½Úµã£¨ 2 ¸öË÷ÒýÒ³£©£¬Ò»²ãÒ¶½Úµã£¨ 250 Ò³£¬Ò²¾ÍÊÇ»ù´¡±íÎïÀí´æ´¢Ò³£©±íµÄÊý¾Ý¼ÙÉè 1w ÐС£×¢£ºËùÓÐÊý¾Ý¾ùΪ¼ÙÉ裬ֻΪ˵Ã÷Ô­Àí¡£
ÎÒÃÇÊ×ÏÈ£¬ÔÙÇ¿µ÷Ò»±é£¬ SQLServer »ñÈ¡Êý¾Ý£¬×ÜÊÇÒÔҳΪµ¥Î»£¬¾ÍËãÊÇÖ»¶ÁÈ¡Ò»ÐÐÒ²»á»ñÈ¡ÕûÕÅÒ³ £¨¼û¡¶Ð´ÓÐЧÂ浀 SQL ²éѯ£¨ I £©¡·£©
ÏÖÔÚÓÐÒ»Ìõ¼òµ¥²éѯ ( È磺 select * from tb where col2 = 99 £¬ col2 ÊÇ tb ±íÖеķǾۼ¯Ë÷Òý ) £¬¼ÙÉè»á·µ»Ø 100 ÐС£
Ok £¬ÎÒÃÇÀ´·ÖÎöÈç¹ûÒÔ Index seek À´²éÕÒÕâ 100 ÐлáÓжàÉÙ IO ¡£ index seek ÿ´Î¶¼´ÓË÷ÒýÊ÷¸ù½Úµã¿ªÊ¼²éÕÒ£¬ÕÒµ½Öм伶½Úµã£¨ 99 ¶ÔÓ¦µÄË÷ÒýÐУ©£¬È»ºó´Ó¸Ã½ÚµãÐпªÊ¼Á¬Ðø±éÀúËùÓÐ col2 Ϊ 99 µÄË÷ÒýÐС£ÔÚ±éÀúÕâЩÐÐʱ£¬Ã¿Äõ½Ò»Ìõ£¬¶¼»áͨ¹ý¸ÃÌõË÷ÒýÐÐÖоۼ¯Ë÷Òý¼üֵȥ¾Û¼¯Ë÷ÒýÊ÷ÖÐ index seek £¬È»ºó´ÓÊý¾ÝÒ³ÖлñÈ¡Êý¾Ý¡£ÔÚ×µÄÇé¿öÏ£¬ col2 Ϊ 99 ¶ÔÓ¦µÄË÷ÒýÐпçÔ½ÁËÈ«²¿ 4 ¸öÒ¶¼¶·Ç¾Û¼¯Ë÷ÒýÒ³£¨µ±È»£¬Õâûɶ¿ÉÄÜÐÔ£¬¾ÙÀý¶øÒÑ£¬ÇÐÎðÉ£©£»Ã¿´Îͨ¹ý¾Û¼¯Ë÷ÒýÊ÷½øÐÐ index seek £¬ IO ¿ªÏú×Çé¿öÏÂÊÇÒ»¸ö¸ù½Úµã£¬Ò»¸öÖм伶½Úµã£¬Ò»¸öÊý¾ÝÒ³ , Ò»¹²Òª seek100 ´Î£¬¿ªÏú 300 ¸öÂß¼­ IO ¡£×ÛÉÏ£¬Í¨¹ý nonclustered index seek ×ܹ²¿ªÏúÊÇ 305 ¸ö IO ¡£
ÒªÖªµÀ£¬ÎÒÃǵĻù´¡±íÊý¾ÝÒ³Ò»¹²²Å 250 Ò³£¬Õâ˵Ã÷ÁËɶ£¿ËµÃ÷¾ÍËãÊÇÎÒ´ÓÍ·µ½Î²É¨ÃèÒ»±é±íÒ²±È noncustered index seek ¿ì¡£Õâʱ£¬ SQL2k5 »á²úÉúÒ»¸öÍêÍêÈ«È«µÄ clustered index scan Ö´Ðмƻ®À´¸ã¶¨±íɨÃè¡£
ºÃÁË£¬ÏÖÔÚÎÒÃÇÔÙÀ´·ÖÎö select * from tb1 where col2 = 1 ¡£¼ÙÉèËüµÄ½á¹û¼¯Îª 5 ÐС£Èç¹ûÕâʱ»¹Êǽ


Ïà¹ØÎĵµ£º

SQL ΪÖ÷±íµÄıһÌõ¼Ç¼£¬ÔÚÖмä±íÖÐͬʱ²åÈë¶àÌõÊý¾Ý

ÓÐʱÎÒÃÇ»áÏñÏÂÃæµÄÇé¿öÒ»Ñù£¬ÎªÖ÷±íµÄıһÌõ¼Ç¼£¬ÔÚÖмä±í(T_Stud_Course ±í)ÖÐͬʱ²åÈë¶àÌõÊý¾Ý
T_Student ±í
Stud_ID
Name
1
Tom
2
Jack
T_Course ±í
Course_ID
Course
1
Chinese
2
English
T_Stud_Course ±í
ID
Stud_ID
Course_ID
1
1
1
2
1
2
3
2
2
 
ÏÖÔÚÎÒÃÇ¿ÉÒÔÏÂÃæµÄ´æ´¢¹ý³ÌÀ ......

SQL Server 2005 ϵͳÊý¾Ý½éÉÜ£ºsys.dm_exec_requests







Õë¶Ô SQL Server ÄÚÕýÔÚÖ´ÐеÄÿ¸öÇëÇó·µ»ØÒ»ÐС£sys.dm_exec_connections
¡¢sys.dm_exec_sessions
 ºÍsys.dm_exec_requests
 ·þÎñÆ÷·¶Î§¶¯Ì¬¹ÜÀíÊÓͼӳÉäµ½ sys.sysprocesses
 ÏµÍ³ÊÓͼ£¨ÏÈǰΪϵͳ±í£©¡£
×¢Ò⣺
ÈôÒªÖ´ÐÐÔÚ SQL Server ÒÔÍâµÄ´úÂ루ÀýÈ磬À©Õ¹´æ´¢¹ý³ÌºÍ·Ö ......

¸ßЧSQL²éѯ֮Ë÷Òý£¨VI£©

ÎÒÃÇÏÈ¿´ NestedLoop ºÍ MergeJoin µÄËã·¨£¨ÒÔÏÂΪÒýÓ㬼û RicCC µÄ¡¶ ͨÍùÐÔÄÜÓÅ»¯µÄÌìÌà - µØÓü JOIN ·½·¨ËµÃ÷ ¡· ):
==================================
NestedLoop:
   foreach rowA in tableA where tableA.col2=?
    {
    search rowsB from tableB where tableB.c ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ