SQL Óï¾äÓÅ»¯
hust ei
JOINÓÅ»¯
MySQLÖÐjoinµÄʵÏÖ²ÉÓõÄÊÇNested Loop JoinËã·¨¡£Í¨¹ýÇý¶¯±íµÄ½á¹û¼¯×÷Ϊѻ·»ù´¡Êý¾Ý£¬È»ºó½«¸Ã½á¹û¼¯ÖеÄÊý¾Ý×÷Ϊ¹ýÂË
Ìõ¼þÒ»ÌõÌõµÄµ½ÏÂÒ»¸ö±íÖвéѯÊý¾Ý£¬×îºóºÏ²¢½á¹û£¬Èç¹û´æÔÚºóÐø±í£¬¹ý³ÌÒ²Èç´Ë¡£
¾¡Á¿¼õÉÙjoinÓï¾äÖÐnested loopÑ»·µÄ´ÎÊý¡£×îÓÐЧµÄ·½·¨ÊÇÈÃÇý¶¯±íµÄ½á¹û¼¯¾¡¿ÉÄܵÄС
ÓÅÏÈÓÅ»¯nested loopÖеÄÄÚ²ãÑ»·
±£Ö¤joinÓï¾äÖб»Çý¶¯±íµÄjoin×Ö¶ÎÒѾ±»Ë÷Òý
Èç¹ûÎÞ·¨Âú×ã3£¬ÇÒÄÚ²ã×ÊÔ´³ä×ãʱ£¬ºÏÀíÉèÖÃjoin buffer£¨join_buffer_size²ÎÊý£©
ORDER BY ÓÅ»¯
ORDER BYµÄʵÏÖÓÐ2ÖÖ£¬Ò»ÖÖÊÇͨ¹ýÓÐÐòË÷ÒýÖ±½ÓÈ¡µÃÓÐÐòµÄÊý¾Ý£»ÁíÍâÒ»ÖÖÔòÐëͨ¹ýMySQLÅÅÐòËã·¨½«´æ´¢ÒýÇæ·µ»ØµÄÊý¾Ý½øÐÐ
ÅÅÐòºó£¬ÔÚ·µ»Ø¸øÓû§¡£
ÀûÓÃË÷ÒýʵÏÖÅÅÐòÊÇMySQLÖÐʵÏÖ½á¹û¼¯ÅÅÐòµÄ×î¼Ñ·½·¨£¬ËùÒÔÔÚÓÅ»¯ORDER BYʱ£¬¾¡¿ÉÄܵÄÀûÓÃÒÑÓеÄË÷ÒýÀ´±ÜÃâʵ¼ÊµÄÅÅÐò£¬
ÉõÖÁ¿ÉÒÔÔö¼ÓË÷Òý×ֶΡ£
µ±Ã»ÓÐË÷Òý¿ÉÓÃʱ£¬MySQLÓÐÒÔϵķ½·¨À´Íê³ÉÅÅÐò£º
È¡³öÂú×ã¹ýÂËÌõ¼þµÄ×÷ΪÅÅÐòÌõ¼þµÄ×ֶΣ¬ÒÔ¼°¿ÉÒÔ¶¨Î»µ½ÐÐÊý¾ÝµÄÐÐÖ¸ÕëÐÅÏ¢£¬ÔÚsort bufferÖнøÐÐʵ¼ÊµÄÅÅÐò£¬È»ºóÀûÓÃÅÅÐòºÃµÄÊý¾Ý¸ù¾ÝÐÐÖ¸ÕëÐÅÏ¢·µ»Ø±íÖÐÈ¡µÃ¿Í»§¶ËÆäËûµÄÇëÇó×Ö¶ÎÊý¾Ý
¸ù¾Ý¹ýÂËÌõ¼þÒ»´ÎÈ¡³öËùÓÐÂú×ãµÄ¿Í»§¶ËÇëÇó×Ö¶ÎÒÔ¼°ÅÅÐò×ֶΣ¬²¢½«²»ÐèÒªÅÅÐòµÄ×ֶηÅÔÚÒ»¿éÄÚ´æÇøÓòÄÚ£¬È»ºóÔÙsort bufferÖн«ÅÅÐò×ֶνøÐÐÅÅÐò£¬×îºóÔÚºÍÆäËûÔÚsort bufferÖÐ×Ö¶Î×éºÏ·µ»Ø¸øÓû§
Ïà¶ÔÀ´Ëµ£¬·½·¨2¿ÉÒÔ¼õÉÙIO£¬µ«ÊÇÐèÒª¸ü¶àµÄÄÚ´æ¿Õ¼ä¡£
ÓÅ»¯Ñ¡Ôñ£º
¼Ó´ómax_length_for_sort_dataÖµ¡£ÒòΪMySQL¸ù¾ÝÕâ¸öÖµÀ´¾ö¶¨ÊÇ·ñʹÓ÷½·¨2.µ±·µ»Ø¸øÓû§µÄ×ֶεÄ×ܳ¤¶ÈСÓÚ¸ÃÖµÊÇ¿ÉÒÔʹÓ÷½·¨2.ËùÒÔÔÚÄÚ´æ¿Õ¼ä³ä×ãʱ£¬Ôö´ó¸ÃÖµ¿ÉÒÔʹÅÅÐò·½·¨2Ö´ÐУ¬´Ó¶ø¸ÄÉÆIO
È¥µô²»±ØÒªµÄ·µ»Ø×Ö¶Î
Ôö´ósort_buffer_sizeµÄ´óС¡£¸ÃÖµ¹ýСµÄ»°£¬»á¶ÔÊý¾Ý·Ö¶ÎµÄÅÅÐò¡£
GROUP BY ÓÅ»¯
MySQLÖÐGROUP BYµÄʵÏÖÓÐ3ÖÐÐÎʽ£¬Ç°2ÖÐʹÓÃË÷ÒýÐÅÏ¢À´GROUP BY£¬×îºóÒ»ÖÖÔòʹÓÃÓÚÍêÈ«ÎÞ·¨Ê¹ÓÃË÷ÒýµÄ³¡¾°¡£
ʹÓÃËÉÉ¢£¨LOOSE£©Ë÷ÒýɨÃèʵÏÖGROUP BY
Æä±¾ÒâÔÚÓÚµ±MySQLÍêÈ«ÀûÓÃË÷ÒýɨÃèÀ´ÊµÏÖGROUP bYʱ£¬²¢²»ÐèҪɨÃèËùÓÐÂú×ãÌõ¼þµÄË÷ÒýÏî¼´¿ÉÍê³É²Ù×÷¡£ÔÚÖ´Ðмƻ®µÄExtraÏî¿ÉÒÔÊä³öÐÅÏ¢“Using index for group-by”
¡£ÕâÖÖʵÏÖÊÇ×î¸ßЧµÄ£¬ÒòΪÌõ¼þ¹ýÂ˵ÄÊä³ö¼´ÊÇÐèÒªµÄ½á¹û¡£ÒªÀûÓø÷½·¨ÐèÂú×ãÒÔÏÂÌõ¼þ£º
GROUP BYÌõ¼þ×ֶαØÐë´¦ÓÚͬһË÷ÒýµÄ×îÇ°ÃæµÄÁ¬Ðø×ֶΣ¨»òÊÇ´æÔڵĵ¥ÁÐË÷Òý£¬µ±¸ÃÌõ¼þ½öΪһÁÐʱ£©
ÔÚʹÓÃÁËGROUP BYµÄÍ
Ïà¹ØÎĵµ£º
Óöµ½MS SQL Server 2005 ÎÞ·¨É¾³ýÊý¾Ý¿â×÷Òµ¡£
¡¡¡¡Ê×ÏÈ£¬ÒÔsaÕË»§µÇ¼£¬²é¿´ÒÔÏÂ2¸ö±íµÄÊý¾Ý£¬Èç¹û²»Îª¿Õ¾ÍÓÐÎÊÌâ¡£
¡¡¡¡Sql´úÂë
¡¡¡¡select¡¡*¡¡from¡¡msdb.dbo.sysmaintplan_subplans
¡¡¡¡select¡¡*¡¡from¡¡msdb.dbo.sysmaintplan_log
¡¡¡¡Èç¹û²»Îª¿Õ£¬Ö´ÐÐÒÔϲÙ×÷£¬»ù±¾Éϲ»Óÿ¼ÂÇɾ³ýÄÄÒ»Ìõ¼Ç¼£¬ÓÐÎÊÌâµÄ×÷Òµ¾Í ......
Óï·¨£º
CREATE [Ë÷ÒýÀàÐÍ] INDEX Ë÷ÒýÃû³Æ
ON ±íÃû(ÁÐÃû)
WITH FILLFACTOR = Ìî³äÒò×ÓÖµ0~100
GO
/*ʵÀý*/
USE ¿âÃû
GO
IF EXISTS
(SELECT * from SYSINDEXES WHERE NAME='IX_TEST_TNAME')--¼ì²âÊÇ·ñÒѾ´æÔÚIX_TEST_TNAMEË÷Òý
DROP INDEX
TEST.IX_TEST_TNAME--Èç¹û´æÔÚÔòɾ³ý
--´´½¨Ë÷Òý
CREATE NONCLUSTER ......
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="Default" value="Default" />
</appSettings>
<connectionStrings>
<add name="Default" connectionString="Data Source=192.168.1.197;User ID ......