Help us understand the problem. What is going on with this article?

pt-visual-explain

More than 5 years have passed since last update.

MySQL の EXPLAIN を見やすくしてくれるツール

お手軽に使ってみる

準備

$ wget http://percona.com/get/pt-visual-explain
$ chmod +x ./pt-visual-explain

テストで使うテーブル

$ # new_table
$ mysql -h ${MYSQL_HOST} -uadmin sample -e 'select * from new_table'
+----+------+-----+
| id | name | age |
+----+------+-----+
|  1 | foo  |   1 |
|  2 | bar  |   2 |
|  3 | bazz |   3 |
+----+------+-----+
$ # new_table2
$ mysql -h ${MYSQL_HOST} -uadmin sample -e 'select * from new_table2'
+------+--------+
| name | profit |
+------+--------+
| bar  |   5000 |
| bazz |   3200 |
| foo  |  10000 |
+------+--------+

普通の EXPALIN

$ mysql -h ${MYSQL_HOST} -uadmin sample \
-e 'explain select new_table.name, new_table.age, new_table2.profit from new_table left join new_table2 on new_table.name = new_table2.name'
+----+-------------+------------+--------+---------------+---------+---------+-----------------------+------+-------+
| id | select_type | table      | type   | possible_keys | key     | key_len | ref                   | rows | Extra |
+----+-------------+------------+--------+---------------+---------+---------+-----------------------+------+-------+
|  1 | SIMPLE      | new_table  | ALL    | NULL          | NULL    | NULL    | NULL                  |    3 |       |
|  1 | SIMPLE      | new_table2 | eq_ref | PRIMARY       | PRIMARY | 182     | sample.new_table.name |    1 |       |
+----+-------------+------------+--------+---------------+---------+---------+-----------------------+------+-------+

EXPAIN の結果を pt-visual-explain に食わせた場合

$ mysql -h ${MYSQL_HOST} -uadmin sample \
-e 'explain select new_table.name, new_table.age, new_table2.profit from new_table left join new_table2 on new_table.name = new_table2.name' \
| ./pt-visual-explain 

JOIN
+- Bookmark lookup
|  +- Table
|  |  table          new_table2
|  |  possible_keys  PRIMARY
|  +- Unique index lookup
|     key            new_table2->PRIMARY
|     possible_keys  PRIMARY
|     key_len        182
|     ref            sample.new_table.name
|     rows           1
+- Table scan
   rows           3
   +- Table
      table          new_table
mapk0y
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした