組合索引:最左優(yōu)先原則
如:組合索引(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"
總結(jié)邦邦,組合索引從最左開始組合翩活,只要包含第一列的查詢都會用到該組合索引
為什么組合索引遵循最左優(yōu)先原則淹朋?
索引方法是Btree涕滋,樹狀的,搜索時(shí)需要從根節(jié)點(diǎn)出發(fā)昭灵,上層節(jié)點(diǎn)對應(yīng)靠左的值歇竟,所以有最左優(yōu)先原則按厘。