Skip to content

最左前缀匹配原则增加一个示例 #2686

Closed
@blueair5

Description

@blueair5

再来看一个常见的面试题:如果有索引 联合索引(a,b,c),查询 a=1 AND c=1 会走索引么?c=1 呢?b=1 AND c=1 呢?

我认为可以增加一个示例,如果是 a = 1 AND c = 1 AND b = 1 的情况下,这个会走索引吗?我在实际的工作中,以为这个只有 a = 1 走了部分索引,实际根据 explain 的执行结果,都走了索引。同理 b = 1 AND c = 1 AND a = 1 也可以走索引,可以看出,只要查询的列在索引中都存在,优化器可以优化这个 where 的查找顺序。

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions