现在的位置: 首页 > 综合 > 正文

Bitmap Index相关

2017年01月10日 ⁄ 综合 ⁄ 共 1531字 ⁄ 字号 评论关闭

学习数据挖掘的课上,看到了这种巧妙的方法,但是没有理解透,所以搜了搜相关知识。如果有错误的地方还请指正,谢谢。

Bitmap Index

wiki上的定义如下:
bitmap
index
 is a special kind of database
index
 that uses bitmaps.
bitmap index是一种使用了bitmap思想的数据库索引。

样例:

ID HasInternet Bitmaps
Y N
1 Yes 1 0
2 No 0 1
3 No 0 1
4 Unspecified 0 0
5 Yes 1 0

ID是对每个条目的索引,HasInternet表示有没有兴趣(有,没有,不确定),所以用2位的bitmap就可以保存这一个column的索引,可以通过位操作获取到有兴趣的或者没有兴趣的人。

特点:

1. 在low-cardinality columns中表现很好

2. 对于大数据量的查询,bitmap index 能更有效的减少响应时间

3. 减少index的占用空间

缺点:

1、在需要频繁更新的时候,效率没有b-tree高


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

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

在数据仓储应用中,连接一个大的fact table和小的dimension table,如star schema,Bitmap index也是非常有效的。
对于fact table 和 dimension table, 可以在fact table中的外键上建立bitmap index.

Cardinality  基数, 集的势

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

与b-tree的区别

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


参考:

http://blog.csdn.net/changtiger/article/details/3342538

http://en.wikipedia.org/wiki/Bitmap_index

抱歉!评论已关闭.