组合索引
语句 | 是否使用索引 | 使用情况 | |
1 | where a=1 and b=2 and c=3; | 是 | a,b,c |
2 | where a=1 and b=2; | 是 | a,b |
3 | where a=1; | 是 | a |
4 | where a=1 or b=2; | 是(当只有 a,b,c列时,一般实际中不会出现这样的情况) | a,b,c |
5 | where a=1 or b=2; | 否(还有其他字段,且查询了这个列时) | |
6 | where a=1 and c=2; | 是 | a |
7 | where a=3 and b>10 and c=7 | 是(范围查询阻断索引) | a,b |
8 | where a=3 and b like '%xx%' and c=7; | 是 | a |
9 | where a in (1,2); | 否 |
当一个表中所有的列都是组合索引的时候,这是一种特殊的情况,正常情况下or是不会使用索引的
---------------------------------------------有时间会把具体的语句执行案例补充一下--------------------------------------------