Mysql explain命令使用和搜索类型介绍

分析语句

explain是mysql中的一个指令,可以用来分析sql语句的执行计划,检测有没有使用到索引。

例如:explain select * from mvs;

select_type搜索的类型
table 搜索的表名
type 搜索的类型
possible_keys 可能用到的索引
key实际用到的索引
key_len 索引的长度
ref关联的字段
rows 扫描的行数
Extra 额外的信息
type 搜索类型

性能由高到低顺序

NULL > system > const > eq_ref > ref> range > index > ALL

NULL 不使用索引直接可以获得结果

explain select count(*) from mvs

system 表中满足条件的记录最多一条

explain select  from (select * from mvs limit 1 ) as a ;

const 表中满足条件的记录最多一条通常会出现在主键和unique索引中

explain select * from mvs where id =1;

eq_ref 表中某一列的值关联另一个表主键列的值,通常出现在联表查询中

explain select * from mvs left join types on types.id = mvs.type id;

ref 通过普通索引查询

explain select * from mvs where title =爱';

range索引范围查询

explain select * from mvs where id < 1000:

index 索引扫描

explain select id from mvs;

all 全表扫描

explain select * from mvs;

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值