explain mysql 查询语句

Explain SQL语句性能测试返回值的具体含义:

 

mysql> explain SELECT `content_id` , `content_old_id`, `content_hasimg` ,`content_time_update`, `content_title_long`, `vhost_content`.`site_id`, `site_domain`, `site_name`, `site_state` FROM `vhost_content` LEFT JOIN `vhost_site` ON `vhost_content`.`site_id` = `vhost_site`.`site_id` WHERE `content_effect` = 1 AND `content_audit` = 1 AND `content_publish` = 1 AND `content_time_update` >= '2012-12-16' AND `vhost_content`.`site_id` LIKE '001001001%' AND 1=1 ORDER BY `content_time_update` desc LIMIT 0 , 25;
+----+-------------+---------------+-------+--------------------------------------------------------------------------+------------------+---------+-------------------------------+------+-----------------------------+
| id | select_type | table         | type  | possible_keys                                                            | key              | key_len | ref                           | rows | Extra                       |
+----+-------------+---------------+-------+--------------------------------------------------------------------------+------------------+---------+-------------------------------+------+-----------------------------+
|  1 | SIMPLE      | vhost_content | range | idx_content_site,Refvhost_site483,idx_content_uptime,idx_content_publish | idx_content_site | 55      | NULL                          |  198 | Using where; Using filesort |
|  1 | SIMPLE      | vhost_site    | ref   | PRIMARY                                                                  | PRIMARY          | 54      | vhostdb.vhost_content.site_id |    1 |                             |
+----+-------------+---------------+-------+--------------------------------------------------------------------------+------------------+---------+-------------------------------+------+-----------------------------+

 

Table:  显示该语句涉及数据库表

Type:  这列很重要, 显示了该连接使用了哪种类别, 有无使用索引,反应语句的质量         。结果值从好到坏依次是 : system > const > eq_ref > ref > fulltext > ref_or_null > index_merge > unique_subquery > index_subquery > range > index > ALL 一般来说,得保证查询至少达到range级别, 最好能到达ref级别, 否则就可能出现性能问题。

Possible_key : 指出mysql能使用哪个索引在该表中找到行

Key: 显示mysql实际使用的键(索引), 如果没有选择索引, 键是null

Key_len 显示mysql决定使用的键长度。 如果是null 则长度为null,在不损失精确性的情况下, 长度越短越好。

Ref 显示使用哪个列或常数与key一起从表中选择行。

Rows: 显示mysql认为它执行查询时必须检查的行数。

Extra 包含mysql解决查询的详细信息。

猜你喜欢

转载自lfq618.iteye.com/blog/1750116