mysql组合索引

2018-01-07  本文已影响0人  gaomumu

组合索引:最左优先原则

如:组合索引(col_a,col_b,col_c)

使用到索引的情况如下:

col_a = "some value"

col_a = "some value" and col_b = "some value"

col_a = "some value" and col_c = "some value"

col_a = "some value" and col_b = "some value" and col_c = "some value"

col_a = "some value" and col_c = "some value" and col_b = "some value"

col_b = "some value" and col_a = "some value" and col_c = "some value"

col_b = "some value" and col_c = "some value" and col_a = "some value"

col_c = "some value" and col_a = "some value" and col_b = "some value"

col_c = "some value" and col_b = "some value" and col_a = "some value"

未使用索引的情况

col_b = "some value"

col_c = "some value"

col_b = "some value" and col_c = "some value"

col_c = "some value" and col_b = "some value"

总结,组合索引从最左开始组合,只要包含第一列的查询都会用到该组合索引

为什么组合索引遵循最左优先原则?

索引方法是Btree,树状的,搜索时需要从根节点出发,上层节点对应靠左的值,所以有最左优先原则。

上一篇下一篇

猜你喜欢

热点阅读