mysql バージョン5.6のexplain
mysql バージョン5.6のexplain
mysql5.6(正確には5.6.3)からselect文以外のDMLでもexplainが使えるように変更されたので試してみた。
データの確認
こんなデータを使ってみる。
mysql> select * from hogetb; +----+------+------+ | id | col1 | col2 | +----+------+------+ | 1 | 10 | 10 | | 2 | 10 | 10 | | 3 | 10 | 10 | +----+------+------+ 3 rows in set (0.01 sec)
select文のexplain
これは今まで通り。
mysql> explain select * from hogetb\G *************************** 1. row *************************** id: 1 select_type: SIMPLE table: hogetb type: ALL possible_keys: NULL key: NULL key_len: NULL ref: NULL rows: 3 Extra: 1 row in set (0.00 sec) mysql> select * from hogetb; +----+------+------+ | id | col1 | col2 | +----+------+------+ | 1 | 10 | 10 | | 2 | 10 | 10 | | 3 | 10 | 10 | +----+------+------+ 3 rows in set (0.00 sec)
delete文のexplain
全件削除、PK指定の削除ともに実行計画が出てますね。当然データは変更されていません。
mysql> explain delete from hogetb\G *************************** 1. row *************************** id: 1 select_type: SIMPLE table: NULL type: NULL possible_keys: NULL key: NULL key_len: NULL ref: NULL rows: 3 Extra: Deleting all rows 1 row in set (0.00 sec) mysql> explain delete from hogetb where id = 1\G *************************** 1. row *************************** id: 1 select_type: SIMPLE table: hogetb type: range possible_keys: PRIMARY key: PRIMARY key_len: 4 ref: NULL rows: 1 Extra: Using where 1 row in set (0.00 sec) mysql> select * from hogetb; +----+------+------+ | id | col1 | col2 | +----+------+------+ | 1 | 10 | 10 | | 2 | 10 | 10 | | 3 | 10 | 10 | +----+------+------+ 3 rows in set (0.00 sec)
update文のexplain
こちらも全件削除、PK指定の削除ともに実行計画が出てますね。当然データは変更されていません。
mysql> explain update hogetb set col1 = 20\G *************************** 1. row *************************** id: 1 select_type: SIMPLE table: hogetb type: ALL possible_keys: PRIMARY key: PRIMARY key_len: 4 ref: NULL rows: 3 Extra: 1 row in set (0.00 sec) mysql> explain update hogetb set col1 = 20 where id = 2\G *************************** 1. row *************************** id: 1 select_type: SIMPLE table: hogetb type: range possible_keys: PRIMARY key: PRIMARY key_len: 4 ref: NULL rows: 1 Extra: Using where 1 row in set (0.01 sec) mysql> select * from hogetb; +----+------+------+ | id | col1 | col2 | +----+------+------+ | 1 | 10 | 10 | | 2 | 10 | 10 | | 3 | 10 | 10 | +----+------+------+ 3 rows in set (0.00 sec)
insert文のexplain
こちらも出来てます。当然データは変更されていません。
mysql> explain insert into hogetb values (null,50,50)\G *************************** 1. row *************************** id: 1 select_type: SIMPLE table: NULL type: NULL possible_keys: NULL key: NULL key_len: NULL ref: NULL rows: NULL Extra: No tables used 1 row in set (0.00 sec) mysql> select * from hogetb; +----+------+------+ | id | col1 | col2 | +----+------+------+ | 1 | 10 | 10 | | 2 | 10 | 10 | | 3 | 10 | 10 | +----+------+------+ 3 rows in set (0.00 sec)
実行計画の作成アルゴリズムとか深いところも気になりますね。