mysql 5.0 是否索引空值?
我意识到之前在堆栈溢出上已经问过确切的问题,只有一个模糊结论性的答案:link< /a>
又来了。
表 A:有一个可为空的整数列以及一个索引。 查询:
SELECT *
FROM table
WHERE column IS NULL
LIMIT 10;
会使用索引,还是mysql会进行全表扫描直到找到10个条目?
I realize that the exact question has been asked before on stack overflow with only a vaguely conclusive answer: link
So here it is again.
Table A: Has an integer column which is nullable, along with an index.
Query:
SELECT *
FROM table
WHERE column IS NULL
LIMIT 10;
Will an index be used, or will mysql do a full table scan until it has found 10 entries?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我认为这应该有帮助:
http://dev.mysql .com/doc/refman/5.0/en/mysql-indexes.html
i think this should be helpful:
http://dev.mysql.com/doc/refman/5.0/en/mysql-indexes.html
确定您的具体情况的唯一方法是在您的查询上运行“EXPLAIN SELECT”。
这实际上取决于表中 NULL 的数量与总行数的比较;表统计信息是否已更新等...
The only way to know that for sure in your specific case is to run "EXPLAIN SELECT" on your query.
It really depends on the number of NULLs in your table compared with total number of rows; whether table statistics have been updated, etc...
您必须分析查询。一般来说,它取决于
NULL
与值的相对百分比。如果该整数列中的大多数条目为 NULL,则它可能会跳过它。另一方面,如果只有 10%(例如)
NULL
,它将(或应该)使用索引。You'd have to analyze the query. In general, it depends on the relative percentage of
NULLs
to values. If a majority of the entries in that integer column is NULL, that it will likely skip it.On the other hand, if only 10% (for example) are
NULL
, it will (or should) use the index.有一种简单的方法可以了解它。
你可以执行这个命令
show index from tablename
,它会返回一些分析结果,其中一个被称为NULL。如果 NULL 等于 YES,则您的索引包含 NULL
http://dev. mysql.com/doc/refman/5.1/en/show-index.html
There is one simple way to know it.
You can execute this command
show index from tablename
and it will return some analysis results which one is called NULL.if NULL equals YES, your index contains NULL
http://dev.mysql.com/doc/refman/5.1/en/show-index.html