MySQL 索引 NULL 值吗?

2021-12-21 00:00:00 indexing null mysql

我有一个 MySQL 表,其中索引 INT 列对于 90% 的行将是 0.如果我将这些行更改为使用 NULL 而不是 0,它们是否会被排除在索引之外,从而使索引小 90% 左右?

I have a MySQL table where an indexed INT column is going to be 0 for 90% of the rows. If I change those rows to use NULL instead of 0, will they be left out of the index, making the index about 90% smaller?

推荐答案

http://dev.mysql.com/doc/refman/5.0/en/is-null-optimization.html

MySQL 可以对 col_name IS NULL 执行相同的优化,它可以用于 col_name = constant_value.例如,MySQL 可以使用索引和范围来搜索 NULLIS NULL.

MySQL can perform the same optimization on col_name IS NULL that it can use for col_name = constant_value. For example, MySQL can use indexes and ranges to search for NULL with IS NULL.

相关文章