Skip to content

修正关于 OR 导致索引失效的描述 #298

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion mysql/index/index_lose.md
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ MySQL 5.5 的话,前面 a 会走索引,在联合索引找到主键值后,

## WHERE 子句中的 OR

在 WHERE 子句中,如果在 OR 前的条件列是索引列,而在 OR 后的条件列不是索引列,那么索引会失效
在 WHERE 子句中,如果 OR 前后的条件列中存在一个列没有创建索引,就会导致整个查询语句索引失效

举个例子,比如下面的查询语句,id 是主键,age 是普通列,从执行计划的结果看,是走了全表扫描。

Expand Down
Loading