索引使用规则4——覆盖索引&回表查询

覆盖索引:查询使用了索引,并且需要返回的列,在索引里面都可以找到,减少select*的使用

1、using index condition

Extra 为using index condition 表明查找使用了索引,但是需要回表查询(也就是先二级索引,拿到id,在返回表里面,进行聚集索引,得到一行的数据,耗时耗内存)

举个例子

explain select * from tb_user where name='码云' and phone='18800008888' and age=55;
explain select id, name, phone,age,gender from tb_user where name='码云' and phone='18800008888' and age=55;

2、using where, using index

Extra为 using where, using index表明查找使用了索引,但是需要的数据在索引里面都可以找到,不需要回表查询

举个例子

explain select id, name, phone from tb_user where name='码云' and phone='18800008888' and age=55;
explain select id, name, phone,age from tb_user where name='码云' and phone='18800008888' and age=55;

总结:尽量不要使用select*,容易出现回表查询,降低查询效率,除非联合索引包含了所有的字段。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值