oracle 索引(Bitmap Index)

来源:互联网 发布:oracle sql declare 编辑:程序博客网 时间:2024/05/01 17:36

一  Bitmap index

Bitmap index 的特点:
1. 对于大数据量的查询,bitmap index 能更有效的减少响应时间
2. 减少index的占用空间

当查询语句的where 字句中包含多个column时, 位图索引最为有效. 因为在查询表之前, 那些有一个不符合所有column条件的row会直接被bitmap index 过滤掉.这样就大大减少了响应时间. 在多数情况下, 一般最好是针对单个column建立bitmap index 而不是组合索引.

创建bitmap index的时候, 必须使用 nologging 和 compute statistics.而且, bitmap index 如果有问题, 最好是直接drop 然后重建而不是去想办法维护它.

Cardinality  基数, 势的集
每个column不同的值的个数叫基数. distinct value. bitmap index 非常适合建在基数比较小的column上, 比如说性别.而且如果说某个table里面有1000000条记录, 而某个column只有1000个不同的值, 相当于记录条数是0.1%. 这种情况下, 使用bitmap index也是不错的.

对于具有唯一约束的或者是基数比较大的column, 比如ID, 最好用普通索引, 即b-tree index.

对于fact table 和 dimension table, 可以在fact table中的外键上建立bitmap index.

bitmap index 和 b-tree 另外一个最大的不同在于对NULL 的处理. bitmap index 可以处理null值, 而b-tree index 则无法存储NULL. 如果是bitmap index 的话, 你可以在where 字句中使用NULL, 如:
select count(*) from customer where customer_long_name is null;
此时, oracle 会使用customer_long_name 上的bitmap_index快速得到值, 甚至不用去真正的access table 上的数据.

但是b-tree无法做到这点因为你无法在b-tree 上存储NULL值. 所以当你执行:
select count(*) from customer 的时候, oracle 会自动从NOT NULL的字段上计算总数.

在partitioned table 上, Bitmap index 只能是local index 而不能是global index.

0 0