MySQL Explain µÄʹÓÃ
¶ÔÓÚʹÓà MySQL Õâ¸öÊý¾Ý¿âϵͳµÄÓû§À´Ëµ£¬Ëü²»½ö¿ªÔ´£¬Îȶ¨£¬Ð§ÂÊÒ²ºÜ¸ß¡£µ«ÓÐʱҲ»áÓöµ½Ò»Ð©ÐÔÄÜ·½ÃæµÄÎÊÌâ¡£Ò»°ãÇé¿ö¿ÉÄÜ»áÓÐÒÔϼ¸ÖÖ¿ÉÄÜ£º
1. Êý¾Ý±íµÄË÷ÒýûÓкÏÀíµÄ½¨ºÃ»òʹÓá£
2. SQLÓï¾ä¹ýÓÚ¸´ÔÓ£¬£¨×ó/ÓÒÁ¬½Ó£¬¶à±í²éѯµÈ£©¡£
3. ·þÎñÆ÷ÅäÖò»ºÏÀí¡£
4. ·þÎñÆ÷±¾ÉíµÄ´¦ÀíÄÜÁ¦²»¼Ñ£¬¸ººÉ²»Æð¡£
µ«ÔÚʵ¼ÊµÄÏîÄ¿Ó¦ÓÃÖУ¬×î·½±ã¿ÉÒÔÓÅ»¯µÄÒ²¾ÍÊÇSQLÓï¾ä¡£ÒÔϾͶÔÓÚSQLµÄÖ´ÐеÄЧÂʽøÐзÖÎö£¬ÎÒÃÇ¿ÉÒÔʹÓÃEXPLAIN/DESCÀ´¼ì²éÕâЩÓï¾ä£¬Ëü¿ÉÒԺܺõØÏÔʾmysqlÈçºÎʹÓÃË÷ÒýÀ´´¦ÀíselectÓï¾äÒÔ¼°Á¬½Ó±í¡£¿ÉÒÔ°ïÖúÑ¡Ôñ¸üºÃµÄË÷ÒýºÍд³ö¸üÓÅ»¯µÄ²éѯÓï¾ä¡£
ʹÓ÷½·¨È磺EXPLAIN SELECT fieldname from tablename WHERE fieldi=$statement;
mysql> explain SELECT * from `album` WHERE aid = 5252 AND del = 0 AND ORDER BY `dateline` DESC LIMIT 4;
+----+-------------+---------+------+---------------+-------+---------+-------+------+-----------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+---------+------+---------------+-------+---------+-------+------+-----------------------------+
| 1 | SIMPLE | album | ref | aid | aid | 4 | const | 1 | Using where; Using filesort |
+----+-------------+---------+------+---------------+-------+---------+-------+------+-----------------------------+
1 row in set (0.00 sec)
Ò»¡¢EXPLAIN ÁеĽâÊÍ£º
table
£ºÏÔʾÕâÒ»ÐеÄÊý¾ÝÊǹØÓÚÄÄÕűíµÄ¡£
type
£º ÕâÊÇÖØÒªµÄÁУ¬ÏÔʾÁ¬½ÓʹÓÃÁ˺ÎÖÖÀàÐÍ¡£´Ó×îºÃµ½×î²îµÄÁ¬½ÓÀàÐÍΪconst¡¢eq_reg¡¢ref¡¢range¡¢indexheºÍALL¡£
possible_keys
£ºÏÔʾ¿ÉÄÜÓ¦ÓÃÔÚÕâÕűíÖеÄË÷Òý¡£Èç¹ûΪ¿Õ£¬Ã»ÓпÉÄܵÄË÷Òý¡£¿ÉÒÔΪÏà¹ØµÄÓò´ÓWHEREÓï¾äÖÐÑ¡ÔñÒ»¸öºÏÊʵÄÓï¾ä¡£
key
£ºÏÔʾMySQLʵ¼Ê¾ö¶¨Ê¹Óõļü(Ë÷Òý)¡£Èç¹
Ïà¹ØÎĵµ£º
1.´´½¨±í£º
create table groupTable(dept varchar(6),phone varchar(20),amount int);
2.²åÈë²âÊÔÊý¾Ý£º
insert groupTable
select 'ÓªÒµ²¿',8001,20 union all
select 'ÓªÒµ²¿',8002,30 union all
se ......
http://www.javaeye.com/topic/211951
Õâ¶Îʱ¼äÔÚ¿´¡¶High Performance MySQL¡·£¬¿´µ½´æ´¢ÒýÇæÕâ¸öµØ·½¸Ðµ½ºÜ¶àϸ½Ú±È½ÏÄ°Éú£¬ËùÒÔ×ܽáС¼ÇһЩ
ΪÁËÊÊÓ¦¸÷ÖÖ²»Í¬µÄÔËÐл·¾³£¬MYSQLÌṩÁ˶àÖÖ²»Í¬µÄ´æ´¢ÒýÇ棨Storage Engine £©,ÔÚÓ¦ÓóÌÐò¿ª·¢Õâ¸ö²ãÃæÉÏ£¬¿ª·¢Õß¿ÉÒÔ¸ù¾Ý²»Í¬µÄÐèÇóÑ¡ÔñÊʺϵÄStorage Engine ·½°¸£¬¸üΪÁ ......
my.iniÎļþÅäÖ㺠[mysql] default-character-set=GBK #´Ë´¦µÄ±àÂëÊÇMySQL¿ØÖÆ̨ÏÔʾµÄ±àÂ뷽ʽ£¬Ó¦¸ÃÉèÖÃΪGBK [mysqld] default-character-set=utf8 #´Ë´¦µÄ±àÂëÊÇMySQLÊý¾Ý´æ´¢µÄ¸ñʽ£¬Ó¦¸ÃÉèÖÃΪutf8£¬¿ÉÒÔ´æ´¢ÊÀ½çÉϾø´ó¶àÊý×Ö·û ......
ÔÚMySQL 3.23.44°æ±¾ºó£¬InnoDBÒýÇæÀàÐ͵ıíÖ§³ÖÁËÍâ¼üÔ¼Êø¡£
Íâ¼üµÄʹÓÃÌõ¼þ£º
1.Á½¸ö±í±ØÐëÊÇInnoDB±í£¬MyISAM±íÔÝʱ²»Ö§³ÖÍâ¼ü£¨¾Ý˵ÒÔºóµÄ°æ±¾ÓпÉÄÜÖ§³Ö£¬µ«ÖÁÉÙÄ¿Ç°²»Ö§³Ö£©£»
2.Íâ¼üÁбØÐ뽨Á¢ÁËË÷Òý£¬MySQL 4.1.2ÒÔºóµÄ°æ±¾ÔÚ½¨Á¢Íâ¼üʱ»á×Ô¶¯´´½¨Ë÷Òý£¬µ«Èç¹ûÔÚ½ÏÔçµÄ°æ±¾ÔòÐèÒªÏÔʾ½¨Á¢£»
3.Íâ¼ü¹ØÏ ......
1.¸´ÖƱí½á¹¹¼°Êý¾Ýµ½Ð±í
CREATE TABLE бí SELECT * from ¾É±í
2.Ö»¸´ÖƱí½á¹¹µ½Ð±í
CREATE TABLE бí SELECT * from ¾É±í WHERE 1=2
»òCREATE TABLE бí LIKE ¾É±í
3.¸´ÖƾɱíµÄÊý¾Ýµ½Ð±í(¼ÙÉèÁ½¸ö±í½á¹¹Ò»Ñù)
INSERT INTO бí SELECT * from ¾É±í
4.¸´ÖƾɱíµÄÊý¾Ýµ½Ð±í(¼ÙÉèÁ½¸ö±í½á¹¹²»Ò»Ñù)
IN ......