本文主要是介绍索引使用规则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*,容易出现回表查询,降低查询效率,除非联合索引包含了所有的字段。
这篇关于索引使用规则4——覆盖索引回表查询的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!