explain之表的连接类型type

mysql之explain分析表
索引类型 primary key ,unique ,normal ,full text

以下是表的连接类型type从最优到最差【查询优化级别type至少达到range】

system>const>eq_ref>ref>ref_or_null>index_merge>unique_subquery
>index_subquery>range>index>all
  • const
    数据表只有一个匹配行,适用于索引类型为primary或unique索引
    示例

EXPLAIN select * from test where id=“1” #primary
EXPLAIN select * from test where name=“a” #name建立了unique索引

  • eq_ref
    对于每个来自于前面的表的行的组合,从该表中读取一行,当一个索引的所有部分都在查询中使用且索引类型为primary或unique时,即可使用这种类型

EXPLAIN SELECT * from test t,test_copy te where t.id=te.id # eq_ref primary

  • ref
    对于每个来自于前面的表的行的组合,从该表中读取一行,当一个索引的所有部分都在查询中使用且索引类型不为primary或unique时,即可使用这种类型

EXPLAIN select * from test where name=“a” #name索引为normal类型

  • ref_or_null
    此类型类似于ref,区别在于行数据为空也可以获取

EXPLAIN select name from test where name=“a” or name IS NULL

  • index_merge
    此类型表示使用了索引合并优化方案
  • unique_subquery
    子查询索引字段的类型为unique或primary时,此处为id字段【建立了主键】

EXPLAIN select name from test where id IN (select id from test)

  • index_subquery
    子查询字段索引类型为normal的子查询

EXPLAIN select * from test where name IN (select name from test) #name索引类型为normal

  • range
    只检索给定范围的行,用索引来选择行

, < ,>=, <=, in , <>, between and ,is null等

EXPLAIN select * from test where id>3

  • index
    与all相似,index扫描索引文件而all扫描数据文件

EXPLAIN SELECT age from test where age<>1

  • all
    全表扫描

EXPLAIN select * from test

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

幽·

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值