Skip to content
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

MySQL 索引问题 #4

Open
Love-OverFlow opened this issue Mar 23, 2023 · 0 comments
Open

MySQL 索引问题 #4

Love-OverFlow opened this issue Mar 23, 2023 · 0 comments

Comments

@Love-OverFlow
Copy link

/main/src/mysql/indexing.md

索引的优化(使用索引的注意事项)

索引不会包含有NULL值的列,IS NULL,IS NOT NULL无法使用索引:

只要列中包含有NULL值都将不会被包含在索引中,复合索引中只要有一列含有NULL值,那么这一列对于此复合索引就是无效的。所以在数据库设计时,尽量使用NOT NULL约束以及默认值。

有误,可以在包含 NULL 的列上建立索引,但是这就会导致优化器在做索引选择的时候更加复杂,性能下降,因为可为 NULL 的列会使索引、索引统计和值比较都更复杂,比如进行索引统计时,count 会省略值为 NULL 的行。 -- 《小林coding

实验:

  1. Mysql在字段为允许null时,存在null值,会不会影响索引使用
  2. 包含 NULL 列的复合索引上的查询也可以走索引
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant