MySQL EXPLAIN Extra列的信息html
这一列包含的是不适合在其余列显示的额外信息。mysql
这意味着mysql服务器将在存储引擎检索行后再进行过滤。许多where条件里涉及索引中的列,当它若是而且读取索引时,就能背存储引擎检验,所以不是全部带有where子句的查询都会显示using where。算法
> explain select * from article where createTime = '1991-10-10 10:10:10' ******************** 1. row ********************* id: 1 select_type: SIMPLE table: article type: ALL possible_keys: key: key_len: ref: rows: 5 Extra: Using where 1 rows in set
这个值表示mysql将使用覆盖索引,以免访问表。不要把覆盖索引和type:index访问类型混淆了。sql
> explain select title,shortName from article ******************** 1. row ********************* id: 1 select_type: SIMPLE table: article type: index possible_keys: key: idx_short_name_title key_len: 514 ref: rows: 5 Extra: Using index 1 rows in set
这意味着mysql会对结果使用一个外部索引排序,而不是按照索引次序从表里读取行。mysql有两种文件排序算法,两种方式均可以在内存或磁盘文件上完成。EXPLAIN不会告诉你mysql将使用哪种文件排序,也不会告诉你排序会在内存里仍是磁盘上完成。
服务器
> explain select * from article order by title,shortName asc ******************** 1. row ********************* id: 1 select_type: SIMPLE table: article type: ALL possible_keys: key: key_len: ref: rows: 5 Extra: Using filesort 1 rows in set
下面的查询和排序都使用了覆盖索引,因此不会出现using filesort,oop
> explain select title,shortName from article order by title,shortName asc ******************** 1. row ********************* id: 1 select_type: SIMPLE table: article type: index possible_keys: key: idx_short_name_title key_len: 514 ref: rows: 5 Extra: Using index 1 rows in set
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过滤。spa
优化效果:ICP能减小引擎层访问基表的次数和MySQL Server访问存储引擎的次数,减小IO次数,提升查询语句性能。code
> explain select * from article where title = 'hello' and shortName like '%hello%' ******************** 1. row ********************* id: 1 select_type: SIMPLE table: article type: ref possible_keys: idx_short_name_title key: idx_short_name_title key_len: 257 ref: const rows: 1 Extra: Using index condition 1 rows in set
这意味着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: 1 select_type: PRIMARY table: a type: const possible_keys: PRIMARY key: PRIMARY key_len: 4 ref: const rows: 1 Extra: ******************** 2. row ********************* id: 2 select_type: UNION table: b type: const possible_keys: PRIMARY key: PRIMARY key_len: 4 ref: const rows: 1 Extra: ******************** 3. row ********************* id: select_type: UNION RESULT table: <union1,2> type: ALL possible_keys: key: key_len: ref: rows: Extra: Using temporary; Using filesort 3 rows in set
单独讲
单独讲
单独讲
============END============