¸ßЧSQL²éѯ֮Ë÷Òý¸²¸Ç(index coverage)
½ñÌì×öSQL ÓÅ»¯£¬²éÕÒÖ´Ðмƻ®Ê±£¬Ö´Ðмƻ®£¬·¢ÏÖ´ËÖ´Ðмƻ®ÓëÒÔÍùµÄ¼Æ»®ÓÐËùÇø±ð£»ÕÒ¼»¥ÁªÍø£¬ÖÕÓÚÕÒһƪÓйØÑо¿±È½ÏÉîÈëµÄÎÄÕ£»
ÔÖ´Ðмƻ®Ê¹ÓõÄÊÇË÷ÒýɨÃ裬ͻȻһÏ»áʹÓÃË÷Òý¸²¸Ç¼¼Êõ£¬Ð§ÂÊ´óÔö£»
SELECT * µÄÕæÏࣺË÷Òý¸²¸Ç(index coverage)
SELECT *µÄЧÂʺÜÔã¸âÂ𣿵±È»£¬ËùÓÐÈ˶¼ÖªµÀÕâÒ»µã£¬µ«ÊÇÎªÊ²Ã´ÄØ£¿
ÊÇÒòΪ·µ»ØÁËÌ«¶àµÄÊý¾Ý£¿
ÕâÊÇÒ»¸öÆÕ±éµÄ»Ø´ð£¬µ«ÎÒ²»ÕâÑùÈÏΪ¡£Èç¹ûÄãµÄÊý¾Ý¿âÉè¼Æ¹æ·¶ºÏÀí£¬ÄÇô´ø¿íÕ¼ÓÃʵ¼ÊÉϷdz£µÄС¡£
ÈÃÎÒÃÇ¿´¿´ÏÂÃæµÄÀý×Ó¡£ÏÂÃæµÄ²éѯ½«»á´ÓAdventureWorks.dbo.TransactionHistoryArchive£¨×ܹ²´óÔ¼Óнü9ÍòÐÐÊý¾Ý£©ÖÐÑ¡Ôñ³ö326ÐÐÊý¾Ý¡£µÚÒ»¸öʹÓÃÁËSELECT * ²éѯ£¬ºóÒ»¸ö²éѯÔòÓÐÃ÷È·µÄ×ֶΡ£
SELECT * from Production.TransactionHistoryArchive
WHERE ReferenceOrderID < 100
SELECT ReferenceOrderLineID from Production.TransactionHistoryArchive
WHERE ReferenceOrderID < 100
ÔÚÕâÖÖÇé¿öÏ£¬Á½ÕßÔÚÍøÂç´ø¿íµÄÇø±ðÖ»ÓÐ15K£¨180K-165K£©£¬´óÔ¼10%µÄ´ø¿í²îÒì¡£µÄÈ·ÖµµÃÈ¥ÓÅ»¯£¬µ«²»»áÓкܴóµÄЧ¹û¡£
SELECT * ½«Ôì³É±í/Ë÷ÒýɨÃè
SELECT * µÄ×î´óÎÊÌâÊǽ«Ó°Ïì²éѯ¼Æ»®¡£SQL ServerÖ÷ҪʹÓÃË÷ÒýÈ¥²éѯÄãÐèÒªµÄÊý¾Ý£¬µ±Ë÷Òý°üÀ¨ËùÓеÄÄãÇëÇó²éѯµÄ×ֶΣ¬SQL Server½«²»ÐèҪȥÔÚ±íÖвéѯ¡£Õâ¸ö¸ÅÄî³Æ×öË÷Òý¸²¸Ç¡£ÔÚÉÏÃæµÄÀý×ÓÖУ¬µÚÒ»¸ö²éѯ½á¹ûÊÇÔÚ¾Û¼¯Ë÷ÒýɨÃèÖУ¬·´¹ýÀ´£¬µÚ¶þ¸öÀý×ÓʹÓÃÁ˸ü¶à¸üÓÐЧÂʵÄË÷ÒýɨÃè¡£ÔÚÕâ¸ö°¸ÀýÖУ¬Ë÷ÒýɨÃè±È¾Û¼¯Ë÷ÒýɨÃè¿ì100±¶ ¡£
³ý·ÇÄãÒѾ½«ÎªÃ¿¸ö×ֶν¨Á¢ÁËË÷Òý£¨ÏÔÈ»²»ÊǸöºÃÖ÷Ò⣩£¬SELECT *ÊDz»Äܹ»ÀûÓõ½Ë÷Òý¸²¸Ç£¬ÄãÖ»ÄÜÈ¥×öɨÃè²Ù×÷£¨·Ç³£µÄûÓÐЧÂÊ£©¡£
Èç¹ûÄãÖ»ÊDzéѯÄãËùÐèÒªµÄ×ֶΣ¬ÄÇÄã¸ü¿ÉÄܵĸ²¸Çµ½ÄãµÄË÷Òý¡£ÎÒÏëÕâ¾ÍÊDz»ÍƼöʹÓÃSELECT *µÄÖ÷ÒªµÄÔÒò¡£
Îȶ¨ÐÔ·½Ãæ
ÔÚά»¤Ò»¸öÓ¦ÓóÌÐòʱ£¬SELECT *Ò²»á´øÀ´Ò»Ð©ÒâÏë²»´óµÄÎÊÌâ¡£Ëü»áÒýÆðÄãµÄ´úÂë·¢ÉúһЩ²»È·¶¨ÐÔ¡£Èç¹ûÄãÔö¼ÓÁËÒ»¸öÐУ¨Òë×¢£ºÎÒ¾õµÃÕâÀïÓ¦¸ÃÊÇ×ֶΣ©µ½Ò»¸ö±íÖУ¬ÄÇôSELECT * ·µ»ØµÄ½á¹ûµ½ÄãµÄÓ¦ÓóÌÐòÖн«»áÔڽṹÉÏ·¢Éú±ä»¯¡£Á¼ºÃµÄÓ¦ÓóÌÐòÓ¦¸ÃÊÇʹÓÃ×Ö¶ÎÃû³ÆµÄ£¬¶ø²»Ó¦¸ÃÊÜ´ËÓ°Ïì¡£µ±Íâ½ç·¢Éú±ä»¯Ê±£¬Á¼ºÃµÄÓ¦ÓóÌÐòÉè¼ÆÒ²Ó¦¸Ã×îС»¯µÄ¸ü¸Ä¡£
Ïà¹ØÎĵµ£º
·ÖÒ³²éѯµÄÔÀí£º
Õâ¸öÖ»ÄÜÓÃÔÙSql2005¼°ÒÔÉϵİ汾
DECLARE @pagenum AS INT, @pagesize AS INT
SET @pagenum = 2
SET @pagesize = 3
SELECT *
from (SELECT ROW_NUMBER()&n ......
ÏÂÔØµØÖ·£ºhttp://msftdbprodsamples.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=19353
ÎÒÏÂÔØµÄÊÇSQL2008.AdventureWorks_All_Databases.x86.msi£¬±¾²»ÏëÏÂÔØÕâÖÖ°²×°Îļþ£¬µ«½Å±¾Îļþ×ÜÊÇÖ´Ðгö´í£¬ÔÒòû¾ßÌåÉ¡£ÕâÖÖ°²×°Îļþ°²×°ºó»á´´½¨Áù¸ö¿âAdventureWorks¡¢AdventureWorks2008¡¢AdventureWorksDW¡¢Ad ......
½ñÌìÔÚÅäÖÃÊý¾Ý¿â·¢²¼ºÍ·Ö·¢Ê±×ÜÊDZ¨³öÏÖ 18483 ´íÎó
Ìáʾ˵£º´íÎó 18483:δÄÜÁ¬½Óµ½·þÎñÆ÷ "XXX"£¬ÒòΪ 'distributor_admin'δÔڸ÷þÎñÆ÷É϶¨ÒåΪԶ³ÌµÇ½¡£
Îҵķ¢²¼ºÍ·Ö·¢ÊÇͬһ¸ö·þÎñÆ÷£¬"XXX" ΪÎҵĻúÆ÷Ãû£¬·Ö·¢Êý¾Ý¿âÊÇĬÈϵÄÃû³Æ£¬¶øÎÒÔÚÁíÍâһ̨»úÆ÷ÉÏ×öʱ¾ÍÕý³£¡£
1¡¢ÉèÖù²Ïí¸´ÖÆÄ¿Â¼:
......
-- ʾÀýÒ», ʹÓÃÖ¤Êé¼ÓÃÜÊý¾Ý.
-- ½¨Á¢²âÊÔÊý¾Ý±í
CREATE TABLE tb(ID int IDENTITY (1,1),data varbinary (8000));
GO
-- ½¨Á¢Ö¤ÊéÒ», ¸ÃÖ¤ÊéʹÓÃÊý¾Ý¿âÖ÷ÃÜÔ¿À´¼ÓÃÜ
CREATE CERTIFICATE Cert_Demo1
WITH
SUBJECT = N'cert1 encryption by database master key' ,
START_DATE = ......
ÏÂÃæÌá³öÁË10ÌõºÍDB2 SQLÐÔÄÜÏà¹ØµÄ10ÌõÒòËØ£º
1¡¢ÌṩÊʵ±µÄͳ¼ÆÐÅÏ¢
¶ÔDB2ÓÅ»¯¹ÜÀíÆ÷£¨otimizer£©¶øÑÔ£¬ÈçºÎ¸ü¼ÓÓÐЧµÄÖ´ÐÐSQLÓï¾äÊÇÓÉ´æÔÚÓÚDB2 catalogÖеÄͳ¼ÆÐÅÏ¢¾ö¶¨µÄ£¬ÓÅ»¯Æ÷ÀûÓÃÕâЩÐÅÏ¢¾ö¶¨×îÓÅ»¯µÄ·¾¶¡£
Òò´Ë£¬ÎªÁ˱£³ÖϵͳÄܹ»×ö³ö×î¼ÑÑ¡Ôñ£¬ÐèÒª¾³£µÄÔËÐÐRunstatsÃüÁÀ´±£³Öϵͳͳ¼ÆÐÅÏ¢µÄ¼°Ê±ÓÐЧ¡£Ô ......