在MySQL5.5版本中,explain查看执行计划,只能支持select语句,但是在MySQL5.6/5.7版本中,可以支持DML语句,即UPDATE、DELETE、INSERT。
建立测试表accessLog和accessLog_bak进行测试:
-
mysql> explain select * from accessLog where id=16649850;
-
+----+-------------+-----------+------------+-------+---------------+---------+---------+-------+------+----------+-------+
-
| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
-
+----+-------------+-----------+------------+-------+---------------+---------+---------+-------+------+----------+-------+
-
| 1 | SIMPLE | accessLog | NULL | const | PRIMARY | PRIMARY | 8 | const | 1 | 100.00 | NULL |
-
+----+-------------+-----------+------------+-------+---------------+---------+---------+-------+------+----------+-------+
-
1 row in set, 1 warning (0.00 sec)
-
-
mysql> explain delete from accessLog where id=16649850;
-
+----+-------------+-----------+------------+-------+---------------+---------+---------+-------+------+----------+-------------+
-
| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
-
+----+-------------+-----------+------------+-------+---------------+---------+---------+-------+------+----------+-------------+
-
| 1 | DELETE | accessLog | NULL | range | PRIMARY | PRIMARY | 8 | const | 1 | 100.00 | Using where |
-
+----+-------------+-----------+------------+-------+---------------+---------+---------+-------+------+----------+-------------+
-
1 row in set (0.00 sec)
-
-
mysql> explain update accessLog_bak set id=111 where id=16649867;
-
+----+-------------+---------------+------------+------+---------------+------+---------+------+--------+----------+-------------+
-
| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
-
+----+-------------+---------------+------------+------+---------------+------+---------+------+--------+----------+-------------+
-
| 1 | UPDATE | accessLog_bak | NULL | ALL | NULL | NULL | NULL | NULL | 582486 | 100.00 | Using where |
-
+----+-------------+---------------+------------+------+---------------+------+---------+------+--------+----------+-------------+
-
1 row in set (0.02 sec)
-
-
mysql> explain insert into accessLog select * from accessLog_bak where id=111;
-
+----+-------------+---------------+------------+------+---------------+------+---------+------+--------+----------+-------------+
-
| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
-
+----+-------------+---------------+------------+------+---------------+------+---------+------+--------+----------+-------------+
-
| 1 | INSERT | accessLog | NULL | ALL | NULL | NULL | NULL | NULL | NULL | NULL | NULL |
-
| 1 | SIMPLE | accessLog_bak | NULL | ALL | NULL | NULL | NULL | NULL | 582486 | 10.00 | Using where |
-
+----+-------------+---------------+------------+------+---------------+------+---------+------+--------+----------+-------------+
-
2 rows in set (0.02 sec)
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/30135314/viewspace-2144572/
,如需转载,请注明出处,否则将追究法律责任。