欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 运维知识 > 数据库 >内容正文

数据库

MySQL EXPLAIN Extra列的信息

发布时间:2025/6/15 数据库 48 豆豆
生活随笔 收集整理的这篇文章主要介绍了 MySQL EXPLAIN Extra列的信息 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

2019独角兽企业重金招聘Python工程师标准>>>

MySQL EXPLAIN Extra列的信息

这一列包含的是不适合在其他列显示的额外信息。

Using where

这意味着mysql服务器将在存储引擎检索行后再进行过滤。许多where条件里涉及索引中的列,当它如果并且读取索引时,就能背存储引擎检验,因此不是所有带有where子句的查询都会显示using where。

> explain  select * from article where createTime = '1991-10-10 10:10:10'******************** 1. row *********************id: 1select_type: SIMPLEtable: articletype: ALL possible_keys: key: key_len: ref: rows: 5Extra: Using where 1 rows in set

Using index

这个值表示mysql将使用覆盖索引,以避免访问表。不要把覆盖索引和type:index访问类型混淆了。

> explain select title,shortName from article******************** 1. row *********************id: 1select_type: SIMPLEtable: articletype: index possible_keys: key: idx_short_name_titlekey_len: 514ref: rows: 5Extra: Using index 1 rows in set

Using filesort

这意味着mysql会对结果使用一个外部索引排序,而不是按照索引次序从表里读取行。mysql有两种文件排序算法,两种方式都可以在内存或磁盘文件上完成。EXPLAIN不会告诉你mysql将使用哪一种文件排序,也不会告诉你排序会在内存里还是磁盘上完成。

> explain select * from article order by title,shortName asc******************** 1. row *********************id: 1select_type: SIMPLEtable: articletype: ALL possible_keys: key: key_len: ref: rows: 5Extra: Using filesort 1 rows in set

下面的查询和排序都使用了覆盖索引,所以不会出现using filesort,

> explain select title,shortName from article order by title,shortName asc******************** 1. row *********************id: 1select_type: SIMPLEtable: articletype: index possible_keys: key: idx_short_name_titlekey_len: 514ref: rows: 5Extra: Using index 1 rows in set

Using index condition

Index Condition Pushdown (ICP)是MySQL 5.6版本中的新特性,是一种在存储引擎层使用索引过滤数据的一种优化方式。

a 当关闭ICP时,index 仅仅是data access 的一种访问方式,存储引擎通过索引回表获取的数据会传递到MySQL Server层进行where条件过滤。

b 当打开ICP时,如果部分where条件能使用索引中的字段,MySQL Server会把这部分下推到引擎层,可以利用index过滤的where条件在存储引擎层进行数据过滤,而非将所有通过index access的结果传递到MySQL server层进行where过滤。

优化效果:ICP能减少引擎层访问基表的次数和MySQL Server访问存储引擎的次数,减少IO次数,提高查询语句性能。

> explain  select * from article where title = 'hello' and shortName like '%hello%'******************** 1. row *********************id: 1select_type: SIMPLEtable: articletype: ref possible_keys: idx_short_name_titlekey: idx_short_name_titlekey_len: 257ref: constrows: 1Extra: Using index condition 1 rows in set

Using temporary

这意味着mysql对查询结果排序时会使用一个临时表。

mysql何时会使用临时表https://dev.mysql.com/doc/refman/5.6/en/internal-temporary-tables.html

> explain  select id , title from article a where a.id = 1 union select id ,title from article b where b.id = 2 order by id******************** 1. row *********************id: 1select_type: PRIMARYtable: atype: const possible_keys: PRIMARYkey: PRIMARYkey_len: 4ref: constrows: 1Extra:  ******************** 2. row *********************id: 2select_type: UNIONtable: btype: const possible_keys: PRIMARYkey: PRIMARYkey_len: 4ref: constrows: 1Extra:  ******************** 3. row *********************id: select_type: UNION RESULTtable: <union1,2>type: ALL possible_keys: key: key_len: ref: rows: Extra: Using temporary; Using filesort 3 rows in set

Using join buffer (Block Nested Loop)

单独讲

Using join buffer (Batched Key Access)

单独讲

Using MRR

单独讲

============END============

转载于:https://my.oschina.net/xinxingegeya/blog/495894

总结

以上是生活随笔为你收集整理的MySQL EXPLAIN Extra列的信息的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。