SQL性能

查询执行计划:explain+SQL语句
id :查询编号(id相同从上往下顺序执行,id不同越大越优先)
select_type:查询类型
SIMPLE:简单查询(不包含子查询,不包含union)
PRIMARY:包含子查询中的主查询(最外层)
SUBQUERY:包含子查询中的子查询(非外层)
DERIVED:衍生查询(用到了临时表)
table :查询表
type :索引类型
效率排序:system>const>eq_ref>ref>range>index>all
system:只有一条数据的体统表;或衍生表只有一条数据的查询
const:仅能查询到一条数据的SQL,用于primary key或unique key
eq_ref:对于每个索引键的查询,返回匹配唯一行数据
ref:非唯一性索引,每个索引查询可以返回多行匹配数据
range:范围查询
index:查询全部索引
all:全表查询
 
system/const: 结果只有一条数据
eq_ref:结果多条;但是每条数据是唯一的 ;
ref:结果多条;但是每条数据是是0或多条 ;
 
possible_keys :预测用到的索引
key :实际使用的索引
key_len :实际索引(索引字段长度:varchar(20))长度
ref :当前索引引用到的其他表的索引
rows:用索引查询到的数据量
Extra :额外信息
using filesort : 性能消耗大,需要额外的一次排序(查询)--排序和查找不是同一字段会出现【select * from person wehre name= 'zs' order by age;(条件字段为索引字段)】
using temporary: 性能消耗大,用到了临时表--分组和查找不是同一字段会出现【select * from person wehre name= 'zs' group by age;(条件字段为索引字段)】
using index:性能提升,索引覆盖,不读取源文件,从索引中获取数据(不需要回表查询)【select age from person where age = 20;(条件字段为索引字段)】
using where:需要回表查询,查完索引,再查表【select name from person where age = 20;(条件字段为索引字段)】
impossible where:不可能出现查询结果【select * from person where name= 'zs' and name='ls';(条件字段为索引字段)】
using join buffer:mysql启用连接缓存(sql语句太low了,mysql帮你做了优化)
 

猜你喜欢

转载自www.cnblogs.com/smiletoyou/p/11979614.html