0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

本番のEXPLAINを可視化する

Posted at

前段

開発環境や、ステージングなどで本番に近いデータがある場合は、下記ツールで可視化できます。

しかし、本番にしかないデータ量でのEXPLAINを可視化するにはどうすればよいでしょうか?

pt-visual-explain を使う

pt-query-digest で有名な Percona Toolkit には

というものがあります。
前段のツールのように、色分けされた可視化はできませんが、tree構造で可視化できます。

table形式

$ cat explain_table.txt
+----+-------------+-----------+------------+------+---------------+------+---------+------+------+----------+-------------+
| id | select_type | table     | partitions | type | possible_keys | key  | key_len | ref  | rows | filtered | Extra       |
+----+-------------+-----------+------------+------+---------------+------+---------+------+------+----------+-------------+
|  1 | SIMPLE      | customers | NULL       | ALL  | NULL          | NULL | NULL    | NULL |    5 |   100.00 | Using where |
+----+-------------+-----------+------------+------+---------------+------+---------+------+------+----------+-------------+
1 row in set, 1 warning (0.00 sec)

$ pt-visual-explain explain_table.txt                                                                                                            
Filter with WHERE
+- Table scan
   rows           5
   +- Table
      table          customers

:pencil: explainは Create Index の例からお借りしました

vertical形式

$ cat explain_vertical.txt
*************************** 1. row ***************************
           id: 1
  select_type: SIMPLE
        table: d
         type: ALL
possible_keys: PRIMARY
          key: NULL
      key_len: NULL
          ref: NULL
         rows: 9
        Extra: Parent of 4 pushed join@1
*************************** 2. row ***************************
           id: 1
  select_type: SIMPLE
        table: de
         type: ref
possible_keys: PRIMARY,emp_no,dept_no
          key: dept_no
      key_len: 4
          ref: employees.d.dept_no
         rows: 5305
        Extra: Child of 'd' in pushed join@1
*************************** 3. row ***************************
           id: 1
  select_type: SIMPLE
        table: e
         type: eq_ref
possible_keys: PRIMARY
          key: PRIMARY
      key_len: 4
          ref: employees.de.emp_no
         rows: 1
        Extra: Child of 'de' in pushed join@1
*************************** 4. row ***************************
           id: 1
  select_type: SIMPLE
        table: t
         type: ref
possible_keys: PRIMARY,emp_no
          key: emp_no
      key_len: 4
          ref: employees.de.emp_no
         rows: 19
        Extra: Child of 'e' in pushed join@1
4 rows in set (0.00 sec)

$ pt-visual-explain explain_vertical.txt                                                                                                                                                                                                                                                                                                      
JOIN
+- Bookmark lookup
|  +- Table
|  |  table          t
|  |  possible_keys  PRIMARY,emp_no
|  +- Index lookup
|     key            t->emp_no
|     possible_keys  PRIMARY,emp_no
|     key_len        4
|     ref            employees.de.emp_no
|     rows           19
+- JOIN
   +- Bookmark lookup
   |  +- Table
   |  |  table          e
   |  |  possible_keys  PRIMARY
   |  +- Unique index lookup
   |     key            e->PRIMARY
   |     possible_keys  PRIMARY
   |     key_len        4
   |     ref            employees.de.emp_no
   |     rows           1
   +- JOIN
      +- Bookmark lookup
      |  +- Table
      |  |  table          de
      |  |  possible_keys  PRIMARY,emp_no,dept_no
      |  +- Index lookup
      |     key            de->dept_no
      |     possible_keys  PRIMARY,emp_no,dept_no
      |     key_len        4
      |     ref            employees.d.dept_no
      |     rows           5305
      +- Table scan
         rows           9
         +- Table
            table          d
            possible_keys  PRIMARY

:pencil: explainは sysvar_ndb_join_pushdown の例からお借りしました

EXPLAIN FORMAT=JSON

pt-visual-explain 3.2.1 では対応していませんでした。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?