bitscn.com explain mysql查询语句
explain sql语句性能测试返回值的具体含义:
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解决查询的详细信息。
bitscn.com
