全部博文(137)
分类: Mysql/postgreSQL
2010-02-23 11:27:12
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)
是否觉得舒服多了?当然实质的内容还是一样的,选择怎么输出就看自己的喜好了。