+ -
当前位置:首页 → 问答吧 → 创建索引的问题

创建索引的问题

时间:2011-09-04

来源:互联网

现有一张非分区表,数据量1亿左右,有个列status,其中99%的值是“正常”,1%的是非正常的,其中非正常的值有200种。此列是否适合创建索引,如果需要的话,创建什么类型的索引?

作者: cj402444206   发布时间: 2011-09-04

你是不是自关注非正常的?

作者: xgghxkhuang   发布时间: 2011-09-04

是的,只关注非正常的。

作者: cj402444206   发布时间: 2011-09-04

FBI

作者: dingjun123   发布时间: 2011-09-04

提供两种方案:
1.可以建立常规单字段0索引,但是得为索引单字段收集直方图
好处:无需修改应用
坏掉:索引较大,而且需要收集直方图,对status字段只能用实际值去访问,不适合使用绑定变量。
总体:不建议用
2.建立函数索引,只对不正常的建立索引
好处:索引小,无需直方图,可以使用绑定变量
坏处:需要用函数索引中的表达式修改应用。
总体:推荐使用
举例如下:

create table test_index
as
select level vi,'A' status
from dual
connect by level<=1000000

update test_index set status='D'
where rownum<=11

commit

create index v11 on test_index ((case when status<>'A' then status end ))

select * from test_index
where status ='A'

select * from test_index
where status ='D'

select * from test_index
where (case when status<>'A' then status end ) ='D'--需要用这种方式去改写引用,同时需要开启数据库用户下的查询改写选项

作者: xgghxkhuang   发布时间: 2011-09-04

热门下载

更多