blog

博客

View on GitHub

多列索引发挥作用,需要满足左前缀要求。

以index(a,b,c)为例:

语句                                  |     索引是否发挥作用
-   -   -   -   -   -   -   -   -   -   -   -   -   - -   
where a=3                             |     是
where a=3 and b=5                     |     是
where a=3 and b=5 and c=4             |     是
where b=3                             |     否
where c=4                             |     否
where a=3 and c=4                     |     a列能用到索引,c不能
where a=3 and b>10 and c=7            |     a能,b能,c不能
where a=3 and b like 'xxx%' and c=7   |     a能,b能,c不能