问题描述
我有一个可空列的索引,我想选择它的所有值如下:
I have an index on a nullable column and I want to select all it's values like this:
SELECT e.ename
FROM emp e;
在解释计划中,我看到一个 FULL TABLE SCAN
(即使提示没有帮助)
In the explain plan I see a FULL TABLE SCAN
(even a hint didn't help)
SELECT e.ename
FROM emp e
WHERE e.ename = 'gdoron';
使用索引...
我googled,发现索引中没有空条目,因此第一个查询不能使用索引。
I googled and found out there are no null entries in indexes, thus the first query can't use the index.
我的问题很简单:为什么索引中不能有空条目
推荐答案
默认情况下,关系数据库忽略NULL值(因为关系模型说NULL表示不存在)。所以,Index不存储NULL值,因此如果你在SQL语句中有空条件,相关的索引被忽略(默认情况下)。
By default, relational databases ignore NULL values (because the relational model says that NULL means "not present"). So, Index does not store NULL value, consequently if you have null condition in SQL statement, related index is ignored (by default).
但你可以超越这个问题,检查或文章。
But you can suprass this problem, check THIS or THIS article.
这篇关于可空列的索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!