美文网首页
MySQL explain extra

MySQL explain extra

作者: 十毛tenmao | 来源:发表于2021-01-23 23:40 被阅读0次

MySQL执行计划中,extra可以展示执行的一些细节,比如索引下推,覆盖索引,排序等信息,为索引优化提供了更完整的信息

常见的extra

extra有很多,这里只列出了最常见的几种类型

  • Using where: 查询条件中
  • Using index condition: 索引下推(Index Condition Pushdown)
  • Using filesort:Server层需要做额外的排序操作,需要优化,让排序使用到索引
  • no matching row in const table:唯一索引(包括主键)查询不到数据
  • Using index:覆盖索引,查询的行都在对应的索引中
  • Using MRR:MRR优化,就是为了减少访问磁盘的次数,回表时,先把主键索引排序后再访问。因为接近的索引,可能在相同的页上
  • Using temporary:使用了临时表,需要优化

疑问

  • 条件中只有一个条件,是索引的第一个字段,也可能Using index condition,这个就太不明白了
CREATE TABLE `user` (
  `id` int NOT NULL AUTO_INCREMENT,
  `name` varchar(32) NOT NULL,
  `email` varchar(32) NOT NULL,
  `address` varchar(128) DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `idx_email` (`email`),
  KEY `idx_name` (`name`),
  KEY `idx_address` (`address`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
mysql> explain select * from user where name like 'hello%';
+----+-------------+-------+------------+-------+---------------+----------+---------+------+------+----------+-----------------------+
| id | select_type | table | partitions | type  | possible_keys | key      | key_len | ref  | rows | filtered | Extra                 |
+----+-------------+-------+------------+-------+---------------+----------+---------+------+------+----------+-----------------------+
|  1 | SIMPLE      | user  | NULL       | range | idx_name      | idx_name | 130     | NULL |    1 |   100.00 | Using index condition |
+----+-------------+-------+------------+-------+---------------+----------+---------+------+------+----------+-----------------------+

参考

相关文章

网友评论

      本文标题:MySQL explain extra

      本文链接:https://www.haomeiwen.com/subject/laypzktx.html