字段不全为空的行可以被索引
如果有这样一种需求,尚未处理的单据,该列为null。已经处理的单据,则将处理人的ID更新到该列。
那么查询尚未处理的单据,就需要查询该列为null的行。
处理这个需求,除了函数索引,还可以使用组合索引。
假设处理人的那个字段就是测试表中的ID字段。
通过创建组合索引,可以使空值的查询,也走这个索引。
如果有这样一种需求,尚未处理的单据,该列为null。已经处理的单据,则将处理人的ID更新到该列。
那么查询尚未处理的单据,就需要查询该列为null的行。
处理这个需求,除了函数索引,还可以使用组合索引。
假设处理人的那个字段就是测试表中的ID字段。
create table test
(
id varchar2(20)
);
begin
for x in 1..10 loop
insert into test values(x);
end loop;
end;
/
create index inx_test_id on test(id,0);
exec dbms_stats.gather_schema_stats('EDMOND');
(
id varchar2(20)
);
begin
for x in 1..10 loop
insert into test values(x);
end loop;
end;
/
create index inx_test_id on test(id,0);
exec dbms_stats.gather_schema_stats('EDMOND');
通过创建组合索引,可以使空值的查询,也走这个索引。
![](http://img.blog.itpub.net/blog/attachment/201401/20/29254281_1390228780TD8Q.png?x-oss-process=style/bb)
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/29254281/viewspace-1073297/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/29254281/viewspace-1073297/