mysql执行计划 const eq_ref ref range index all

explain:查询查询性能或者须要查看使用索引状态
sql

1、type:链接类型  最关键的一列  效率(const>eq_ref>ref>range>index>all)性能

一、const:查询索引字段,而且表中最多只有一行匹配(好像只有主键查询只匹配一行才会是const,有些状况惟一索引匹配一行会是ref)优化

二、eq_ref    主键或者惟一索引  .net

三、ref   非惟一索引(主键也是惟一索引)blog

四、range  索引的范围查询排序

五、index  (type=index extra = using index 表明索引覆盖,即不须要回表)索引

六、all 全表扫描(一般没有建索引的列)内存

2、key_lentable

索引的长度,在不损失精度的状况下越短越好效率

3、ref

4、rows (内循环的次数)

 

5、extra

重要的几个

一、using temporary(组合查询返回的数据量太大须要创建一个临时表存储数据,出现这个sql应该优化)

二、using where (where查询条件)

三、using index(判断是否仅使用索引查询,使用索引树而且不须要回表查询)

四、using filesort(order by 太占内存,使用文件排序)

了解的几个

一、const row not found(听说是当表为空的时候展现,我用了个空表explain以后发现extra列是空值)

二、deleting all rows (MYISAM存储引擎快速清空表)

三、first_match(select * from a where name in(select a_name from B) ,B中有n条记录都记录了同一个a_name,每一个a_name都只会匹配一次。exist也有一样的效果)

四、impossible having, impssible where  (错误的having 和where如,where 1<0)

五、Impossible WHERE noticed after reading const tables(如 where id =1 and name = "temp",表中不存在id=1而且name=temp的记录)

 

附带一个详细的extra连接:https://blog.csdn.net/poxiaonie/article/details/77757471