问题描述
我曾经认为,当其中一个列值为空时,Oracle 不会索引行.
I used to think that Oracle does not index a row when one of the column values is null.
一些简单的实验表明情况并非如此.即使某些列可以为空,我也能够意外地运行一些仅访问索引的查询(这当然是一个惊喜).
Some simple experimentation shows this to be not the case. I was able to run some queries unexpectedly accessing only indexes even though some columns were nullable (which of course was a pleasant surprise).
谷歌搜索导致一些博客的答案相互矛盾:我读过除非所有索引列都为空,否则一行被索引,并且除非前导列,一行被索引索引的值为空.
A Google search led to some blogs with conflicting answers: I have read that a row gets indexed unless all indexed columns are null, and also that a row gets indexed unless the leading column value for the index is null.
那么,在什么情况下一行不进入索引?这个 Oracle 版本是特定的吗?
So, in what cases does a row not enter an index? Is this Oracle version specific?
推荐答案
如果任何索引列包含非空值,该行将被索引.正如您在下面的示例中所看到的,只有一行没有被索引,而且这行在两个索引列中都为 NULL.您还可以看到,当前导索引列具有 NULL 值时,Oracle 肯定会索引一行.
If any indexed column contains a non-null value that row will be indexed. As you can see in the following example only one row doesn't get indexed and that's the row which has NULL in both indexed columns. You can also see that Oracle definitely does index a row when the leading index column has a NULL value.
此示例在 Oracle 11.1.0.6 上运行.但我非常有信心它适用于所有版本.
This example run on Oracle 11.1.0.6. But I'm pretty confident it holds true for all versions.
这篇关于Oracle 何时索引空列值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!