Mysql percona-toolkit工具--pt-visual-explain(二)

Mysql percona-toolkit工具包的安装和使用
http://www.cndba.cn/leo1990/article/2788

2.2 pt-visual-explain

格式化explain出来的执行计划按照tree方式输出,方便阅读

2.2.1 查看包含explain结果的a.sql文件的范例:

[[email protected] ~]#  mysql -uroot -proot -e 'explain select * from sakila.film_actor join sakila.film using(film_id)' > a.sql
[[email protected] ~]# pt-visual-explain /root/a.sql
JOIN
+- Bookmark lookup
|  +- Table
|  |  table          film_actor
|  |  possible_keys  idx_fk_film_id
|  +- Index lookup
|     key            film_actor->idx_fk_film_id
|     possible_keys  idx_fk_film_id
|     key_len        2
|     ref            sakila.film.film_id
|     rows           2
+- Table scan
   rows           1000
   +- Table
      table          film
      possible_keys  PRIMARY

2.2.2 查看包含查询语句的select.out文件的范例:

[[email protected] ~]# echo "select * from sakila.film_actor join sakila.film using(film_id)" > select.out
[[email protected] ~]# pt-visual-explain --connect /root/select.out --user=root --password=root --host=192.168.1.67
JOIN
+- Bookmark lookup
|  +- Table
|  |  table          film_actor
|  |  possible_keys  idx_fk_film_id
|  +- Index lookup
|     key            film_actor->idx_fk_film_id
|     possible_keys  idx_fk_film_id
|     key_len        2
|     ref            sakila.film.film_id
|     rows           2
+- Table scan
   rows           1000
   +- Table
      table          film
      possible_keys  PRIMARY

2.2.3 通过管道直接查看explain输出结果的范例:

[[email protected] XinMonitorClient]# mysql -uroot -proot -e "explain select * from sakila.film_actor join sakila.film using(film_id)" | pt-visual-explain
JOIN
+- Bookmark lookup
|  +- Table
|  |  table          film_actor
|  |  possible_keys  idx_fk_film_id
|  +- Index lookup
|     key            film_actor->idx_fk_film_id
|     possible_keys  idx_fk_film_id
|     key_len        2
|     ref            sakila.film.film_id
|     rows           1
+- Table scan
   rows           1000
   +- Table
      table          film
      possible_keys  PRIMARY

你可能感兴趣的:(工具)