复合索引与单列索引
单列索引
- where mobile=1 and password=12 如果分别建立了两个独立索引,mobile和password,只有一个用到索引,系统根据索引名的排序来决定使用那一个


复合索引
- 使用场景
- where mobile=1 and password=12 多个字段要同时作为查询条件
- 避免冗余
- 合理创建复合索引(避免冗余),(a,b,c) 相当于 (a) 、(a,b) 、(a,b,c)。
- 索引顺序
- 左前缀失效
- like查询是以%开头都会导致左前缀失效
- != < > not in() order by group by都会导致左前缀失效
