访问类型,这里只列出最常见的6种类型
all,index,range,ref,eq_ref,const
mysql中explain的type的解释_dennis211的博客-CSDN博客_explain type
使用不同的运算符时访问类型不一样:
- !=、not in、<>、>、<、in(多个值)、or、between and、like(前面没有%),它的type是range,not like不走索引
- 排序type是index
如何优化查询
- 不要在索引列上进行运算或使用函数
- 小心隐式类型转
当id为varchar类型
select * from article where id = 100,不走索引
当id为int类型
select * from article where id = "100",走索引
- 最左前缀原则,例如创建一个复合索引name, price, num,相当于创建三个索引name,(name,price),(name,price,num)