Mysql管理必备工具Maatkit详解之八(mk-visual-explain)

2009年05月26日 作者: 大头刚 

mk-visual-explain - 格式化mysql执行计划输出。安装方法可以参考这里
Mysql默认的执行计划输出类似如下:

mysql> explain select count(*) from test a,test2 b where a.id<100 and b.id>160 and a.id=b.id;
+----+-------------+-------+--------+---------------+---------+---------+----------------+------+-------------+
| id | select_type | table | type   | possible_keys | key     | key_len | ref            | rows | Extra       |
+----+-------------+-------+--------+---------------+---------+---------+----------------+------+-------------+
|  1 | SIMPLE      | b     | range  | uid           | id     | 4       | NULL           |   30 | Using where | 
|  1 | SIMPLE      | a     | eq_ref | PRIMARY       | PRIMARY | 4       | b.uid |    1 | Using index | 
+----+-------------+-------+--------+---------------+---------+---------+----------------+------+-------------+
2 rows in set (0.00 sec)

使人觉得很单一、没有层次感,那么可以使用这个工具来转化成树状结构。

mysql> pager mk-visual-explain;
PAGER set to 'mk-visual-explain'
mysql> explain select count(*) from test a,test2 b where a.id<100 and b.id>160 and a.id=b.id;
JOIN
+- Unique index lookup
|  key            a->PRIMARY
|  possible_keys  PRIMARY
|  key_len        4
|  ref            b.id
|  rows           1
+- Filter with WHERE
   +- Bookmark lookup
      +- Table
      |  table          b
      |  possible_keys  id
      +- Index range scan
         key            b->id
         possible_keys  id
         key_len        4
         rows           30
2 rows in set (0.00 sec)

是否觉得舒服多了?当然实质的内容还是一样的,选择怎么输出就看自己的喜好了。

  • Comments (0)
  • Trackbacks (0)
Leave a comment Trackback

No comments yet.

No trackback yet.