美文网首页
mysql组合索引

mysql组合索引

作者: gaomumu | 来源:发表于2018-01-07 16:19 被阅读0次

    组合索引:最左优先原则

    如:组合索引(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,树状的,搜索时需要从根节点出发,上层节点对应靠左的值,所以有最左优先原则。

    相关文章

      网友评论

          本文标题:mysql组合索引

          本文链接:https://www.haomeiwen.com/subject/fhapnxtx.html