覆蓋索引:查詢使用了索引,并且需要返回的列,在索引里面都可以找到,減少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*,容易出現回表查詢,降低查詢效率,除非聯合索引包含了所有的字段。