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

MysqlÖ®EXPLAINÏÔʾusing filesort

EXPLAIN ÊÇmysql½âÊÍselect²éѯµÄÒ»¸ö¹Ø¼ü×Ö,¿ÉÒԺܷ½±ãµÄÓÃÓÚµ÷ÊÔ
Óï·¨¸ñʽÈçÏÂ
EXPLAIN tbl_name
»òÕß:
EXPLAIN SELECT select_options
EXPLAIN Óï¾ä¿ÉÒÔ±»µ±×÷ DESCRIBE µÄͬÒå´ÊÀ´Óã¬Ò²¿ÉÒÔÓÃÀ´»ñÈ¡Ò»¸öMySQLÒªÖ´ÐÐµÄ SELECT Óï¾äµÄÏà¹ØÐÅÏ¢¡£
EXPLAIN tbl_name Óï·¨ºÍ DESCRIBE tbl_name »ò SHOW COLUMNS from tbl_name Ò»Ñù¡£
µ±ÔÚÒ»¸ö SELECT Óï¾äǰʹÓùؼü×Ö EXPLAIN ʱ£¬MYSQL»á½âÊÍÁ˼´½«ÈçºÎÔËÐиà SELECT Óï¾ä£¬ËüÏÔʾÁ˱íÈçºÎÁ¬½Ó¡¢Á¬½ÓµÄ˳ÐòµÈÐÅÏ¢¡£
ÒÔÏÂÐÅϢΪÒýÓÃ:
ÔÚexplainÎÒÃÇËùʹÓõÄsqlµÄʱºò£¬¾­³£»áÓöµ½using filesortÕâÖÖÇé¿ö£¬Ô­ÒÔΪÊÇÓÉÓÚÓÐÏàͬÁÐÖµµÄÔ­ÒòÒýÆ𣬽á¹û×òÌì¿´µ½¹«Ë¾µÄÒ»¸ösql£¬¸úͬÊÂÌÖÂÛÁËϼÓÉÏ×Ô¼ºÓÖ×öÁËһЩ²âÊÔ£¬Í»È»·¢ÏÖ×Ô¼ºÔ­À´µÄÏë·¨ÊÇ´íÎóµÄ¡£
Ê×ÏÈ£¬Ö»ÓÐÔÚorder by Êý¾ÝÁеÄʱºò²Å¿ÉÄÜ»á³öÏÖusing filesort£¬¶øÇÒÈç¹ûÄã²»¶Ô½øÐÐorder byµÄÕâÒ»ÁÐÉèÖÃË÷ÒýµÄ»°£¬ÎÞÂÛÁÐÖµÊÇ·ñÓÐÏàͬµÄ¶¼»á³öÏÖusing filesort¡£Òò´Ë£¬Ö»ÒªÓõ½order by µÄÕâÒ»Áж¼Ó¦¸ÃΪÆ佨Á¢Ò»¸öË÷Òý¡£
Æä´Î£¬ÔÚÕâ´Î²âÊÔÖУ¬Ê¹ÓÃÁËÒ»¸öÉÔ΢Óе㸴ÔÓµÄÀý×ÓÀ´ËµÃ÷Õâ¸öÎÊÌ⣬ÏÂÃæÏêϸÓÃÕâ¸öÀý×Ó˵һÏ£º
SELECT * from DB.TB WHERE ID=2222 AND FID IN (9,8,3,13,38,40) ORDER BY INVERSE_DATE LIMIT 0, 5
ÀïÃ潨Á¢µÄË÷ÒýΪһ¸öÈýÁеĶàÁÐË÷Òý£ºIDX£¨ID,FID ,INVERSE_DATE£© ¡£INVERSE_DATEÕâ¸öÊÇʱ¼äµÄ·´ÏòË÷Òý¡£
¶ÔÓÚÕâ¸ösqlÎÒµ±Ê±×ʼÈÏΪӦ¸ÃÊǸöÓÅ»¯ºÃµÄ״̬£¬Ó¦¸ÃûÓÐʲôç¢Â©ÁË£¬½á¹ûÒ»explain²Å·¢ÏÖ¾¹È»³öÏÖÁË£ºUsing where; Using filesort¡£
ΪʲôÄØ£¬ºóÀ´¾­¹ý·ÖÎö²ÅµÃÖª£¬Ô­À´ÔÚ¶àÁÐË÷ÒýÔÚ½¨Á¢µÄʱºòÊÇÒÔB-Ê÷½á¹¹½¨Á¢µÄ£¬Òò´Ë½¨Á¢Ë÷ÒýµÄʱºòÊÇÏȽ¨Á¢IDµÄ°´Ë³ÐòÅŵÄË÷Òý£¬ÔÚÏàͬIDµÄÇé¿öϽ¨Á¢FID°´ ˳ÐòÅŵÄË÷Òý£¬×îºóÔÚFID ÏàͬµÄÇé¿öϽ¨Á¢°´INVERSE_DATE˳ÐòÅŵÄË÷Òý£¬Èç¹ûÁÐÊý¸ü¶àÒÔ´ËÀàÍÆ¡£ÓÐÁËÕâ¸öÀíÂÛÒÀ¾ÝÎÒÃÇ¿ÉÒÔ¿´³öÔÚÕâ¸ösqlʹÓÃÕâ¸öIDXË÷ÒýµÄʱºòÖ»ÊÇÓÃÔÚÁËorder by֮ǰ£¬order by INVERSE_DATE ʵ¼ÊÉÏÊÇusing filesort³öÀ´µÄ¡£¡£º¹ËÀÁË¡£¡£Òò´ËÈç¹ûÎÒÃÇÒªÔÚÓÅ»¯Ò»ÏÂÕâ¸ösql¾ÍÓ¦¸ÃΪËü½¨Á¢ÁíÒ»¸öË÷ÒýIDX£¨ID,INVERSE_DATE£©£¬ÕâÑù¾ÍÏû³ýÁËusing filesortËÙ¶ÈÒ²»á¿ìºÜ¶à¡£ÎÊÌâÖÕÓÚ½â¾öÁË¡£


Ïà¹ØÎĵµ£º

MySQLÒýÇæ

¡¡MySQLµÄ×Ô´øÒýÇæ¿Ï¶¨Êǹ»ÓÃÁË£¬µ«ÊÇÔÚÓÐЩÇé¿öÏ£¬ÆäËûµÄÒýÇæ¿ÉÄÜÒª±ÈÊÖÍ·ËùÓøüÊʺÏÍê³ÉÈÎÎñ¡£Èç¹ûÔ¸ÒâµÄ»°£¬ÄãÉõÖÁ¿ÉÒÔʹÓÃMySQL++ APIÀ´´´½¨×Ô¼ºµÄÊý¾Ý¿âÒýÇ棬¾ÍÏñ´ò´©Æø¸××°ÉÏ×Ô¼ºµÄ»¯ÓÍÆ÷¡£ÏÖÔÚÈÃÎÒÃÇÀ´¿´¿´Äã¸ÃÈçºÎÑ¡ÔñÒýÇ棬ÒÔ¼°ÈçºÎÔÚ¿ÉÓÃÒýÇæÖ®¼äÇл»¡£
¡¡¡¡
¡¡¡¡Ñ¡ÔñÄãµÄÒýÇæ
¡¡¡¡
¡¡¡¡ÄãÄÜÓõÄÊý¾Ý¿ ......

MySQL²éѯ±íÄÚÖظ´¼Ç¼

MySQL²éѯ±íÄÚÖظ´¼Ç¼
 
²éѯ¼°É¾³ýÖظ´¼Ç¼µÄ·½·¨
(Ò»)
1¡¢²éÕÒ±íÖжàÓàµÄÖظ´¼Ç¼£¬Öظ´¼Ç¼ÊǸù¾Ýµ¥¸ö×ֶΣ¨peopleId£©À´ÅжÏ
select * from people
where peopleId in (select peopleId from people group by peopleId having count(peopleId) > 1)
2¡¢É¾³ý±íÖжàÓàµÄÖظ´¼Ç¼£¬Öظ´¼Ç¼ÊǸù¾Ýµ¥¸ö×ֶΠ......

MySQL Ãâ°²×°°æÅäÖÃ

1.ÏÂÔØ MySQL 6.0Ãâ°²×°°æ
http://www.mysql.com/downloads/mirror.php?id=386828
2.½« MySQL6.0 ½âѹµ½´ý°²×°Ä¿Â¼(×Ô¼º¾ö¶¨·Åµ½ÄÄ£©¡£½âѹºóĬÈÏÎļþ¼ÐÃû³ÆΪ£ºmysql£¨µ±È»¿ÉÒÔ×Ô¼º¸ü¸Ä£©£¬È»ºóÔÚ»·¾³±äÁ¿ÖÐÉèÖÃMYSQL_HOME£¨ÕâÑù£¬ÒÔºó¿ÉÒÔÓÃ%MYSQL_HOME%ÒýÓð²×°Ä¿Â¼£©¡£È磬ÎÒ·ÅÔÚEÅ̸ùĿ¼Ï£¬ËùÒÔ£¬MYSQL_HOMEÉèÖÃΪ ......

mysql Óï¾äÓÅ»¯²éѯ

ÎÒÓõÄÊÇmysql5.0£¬
ÎÒ³ÌÐòÖÐÓõ½ÁËÒ»¾äsqlÊÇ
SQL code
select count(DISTINCT id) from Policyinfo p where p.filename not in
(select p2.filename from Policyreadinfo p2 where p2.reader='test')
µ«ÊÇÿ´ÎÔÚ³ÌÐòÖÐÿ´ÎÖ´ÐÐÕâ¾äsqlʱÍøÒ³¾ÍÌØÂý£¬Òª10¶àÃ룬¶øÕâ2¸ö±íµÄ¼Ç¼ÐÐÊýÒ²¾Í1000¶à¶øÒÑ£¬ÎÒ°ÑÕâ¾äsqlµ¥¶ÀÄ ......

MySQL Order ByË÷ÒýÓÅ»¯

ÔÚһЩÇé¿öÏ£¬MySQL¿ÉÒÔÖ±½ÓʹÓÃË÷ÒýÀ´Âú×ãÒ»¸ö ORDER BY »ò GROUP BY ×Ó¾ä¶øÎÞÐè×ö¶îÍâµÄÅÅÐò¡£¾¡¹Ü ORDER BY ²»ÊǺÍË÷ÒýµÄ˳Ðò׼ȷƥÅ䣬Ë÷Òý»¹ÊÇ¿ÉÒÔ±»Óõ½£¬Ö»Òª²»ÓõÄË÷Òý²¿·ÖºÍËùÓеĶîÍâµÄ ORDER BY ×Ö¶ÎÔÚ WHERE ×Ó¾äÖж¼±»°üÀ¨ÁË¡£ ¡¡¡¡Ê¹ÓÃË÷ÒýµÄMySQL Order By ¡¡¡¡ÏÂÁеļ¸¸ö²éѯ¶¼»áʹÓÃË÷ÒýÀ´½â¾ö ORDER BY ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ