Oracle 索引 - 对于空值

Oracle Index - For null values

我阅读了索引,但我不确定我是否正确理解了这一点。请详细说明这一点。

是位图还是btree索引不适用于null

我在 hr.employees.first_Name 和 hr.employees.Last_name 上创建了 b 树索引。
Last_name 不为空 属性 其中 first_name 可以为空。

当我从员工 select last_name 执行索引全扫描时,当我执行 select first_name 来自员工 它正在 table 访问权限已满。

在 Oracle 中,b 树索引不包含有关空键的信息。意思是:

create table X (i integer, j integer);

create index X_j on X(j);

insert into X values (1, 1);      -- record would be indexed
insert into X values (2, 2);      -- record would be indexed
insert into X values (3, null);   -- record would not be indexed

select rowid from X;                       -- index cannot be used
select rowid from X where j = 1;           -- index can be used
select rowid from X where j is not null;   -- index can be used
select rowid from X where j is null;       -- index cannot be used

如果索引多列,如果至少一列不为空值,则索引将包含记录。

如果索引是基于函数的,则表达式结果存在相同的规则。

位图索引包含空键。它们的 null 和 not null 值没有任何区别。

这并不意味着如果您想捕获空值就应该使用位图索引。位图索引在更新时需要独占访问,因此不能用于 OLTP 环境。如果您希望通过索引捕获空值,请使用基于函数的索引将空值转换为一些非空值,比如

create index employee_firstname_fbi on employees('x' || first_name);
select * from employees where 'x' || first_name = 'x';