在MySQL5.5版本中,explain查看执行计划,只能支持select语句,但是在MySQL5.6/5.7版本中,可以支持DML语句,即UPDATE、DELETE、INSERT。
建立测试表accessLog和accessLog_bak进行测试:
建立测试表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)