数据库
首页 > 数据库> > MySQL5.7新特性之explain UPDATE/DELETE/INSERT

MySQL5.7新特性之explain UPDATE/DELETE/INSERT

作者:互联网

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

点击(此处)折叠或打开

  1. mysql> explain select * from accessLog where id=16649850;
  2. +----+-------------+-----------+------------+-------+---------------+---------+---------+-------+------+----------+-------+
  3. | id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
  4. +----+-------------+-----------+------------+-------+---------------+---------+---------+-------+------+----------+-------+
  5. | 1 | SIMPLE | accessLog | NULL | const | PRIMARY | PRIMARY | 8 | const | 1 | 100.00 | NULL |
  6. +----+-------------+-----------+------------+-------+---------------+---------+---------+-------+------+----------+-------+
  7. 1 row in set, 1 warning (0.00 sec)

  8. mysql> explain delete from accessLog where id=16649850;
  9. +----+-------------+-----------+------------+-------+---------------+---------+---------+-------+------+----------+-------------+
  10. | id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
  11. +----+-------------+-----------+------------+-------+---------------+---------+---------+-------+------+----------+-------------+
  12. | 1 | DELETE | accessLog | NULL | range | PRIMARY | PRIMARY | 8 | const | 1 | 100.00 | Using where |
  13. +----+-------------+-----------+------------+-------+---------------+---------+---------+-------+------+----------+-------------+
  14. 1 row in set (0.00 sec)

  15. mysql> explain update accessLog_bak set id=111 where id=16649867;
  16. +----+-------------+---------------+------------+------+---------------+------+---------+------+--------+----------+-------------+
  17. | id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
  18. +----+-------------+---------------+------------+------+---------------+------+---------+------+--------+----------+-------------+
  19. | 1 | UPDATE | accessLog_bak | NULL | ALL | NULL | NULL | NULL | NULL | 582486 | 100.00 | Using where |
  20. +----+-------------+---------------+------------+------+---------------+------+---------+------+--------+----------+-------------+
  21. 1 row in set (0.02 sec)

  22. mysql> explain insert into accessLog select * from accessLog_bak where id=111;
  23. +----+-------------+---------------+------------+------+---------------+------+---------+------+--------+----------+-------------+
  24. | id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
  25. +----+-------------+---------------+------------+------+---------------+------+---------+------+--------+----------+-------------+
  26. | 1 | INSERT | accessLog | NULL | ALL | NULL | NULL | NULL | NULL | NULL | NULL | NULL |
  27. | 1 | SIMPLE | accessLog_bak | NULL | ALL | NULL | NULL | NULL | NULL | 582486 | 10.00 | Using where |
  28. +----+-------------+---------------+------------+------+---------------+------+---------+------+--------+----------+-------------+
  29. 2 rows in set (0.02 sec)


标签:INSERT,accessLog,MySQL5.7,UPDATE,key,NULL,type,id,select
来源: https://blog.51cto.com/u_12592884/2693908