位图索引(二)

2014-11-24 17:08:37 · 作者: · 浏览: 3
----------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | ------------------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 1 | 37 | 3 (0)| 00:00:01 | | 1 | TABLE ACCESS BY INDEX ROWID | EMP | 1 | 37 | 3 (0)| 00:00:01 | | 2 | BITMAP CONVERSION TO ROWIDS| | | | | | |* 3 | BITMAP INDEX SINGLE VALUE | EMP_BTIDX1 | | | | | ------------------------------------------------------------------------------------------- Predicate Information (identified by operation id): --------------------------------------------------- 3 - access("ENAME" IS NULL) Statistics ---------------------------------------------------------- 1 recursive calls 0 db block gets 2 consistent gets 0 physical reads 0 redo size 1003 bytes sent via SQL*Net to client 523 bytes received via SQL*Net from client 2 SQL*Net roundtrips to/from client 0 sorts (memory) 0 sorts (disk) 1 rows processed SQL>

分区表与位图索引:

位图索引只能在分区表上创建本地索引,不能创建全局索引:

SQL> create bitmap index achivement_btidx1 on achivement(id);
create bitmap index achivement_btidx1 on achivement(id)
                                         *
ERROR at line 1:
ORA-25122: Only LOCAL bitmap indexes are permitted on partitioned tables


SQL> create bitmap index achivement_btidx1 on achivement(id) local nologging;

Index created.

SQL> drop index achivement_btidx1;

Index dropped.

SQL> create bitmap index achivement_btidx1 on achivement(id) global;
create bitmap index achivement_btidx1 on achivement(id) global
                                                        *
ERROR at line 1:
ORA-25113: GLOBAL may not be used with a bitmap index


SQL> 
索引组织表与位图索引:
在索引组织表上创建二级位图索引必须指定映射表mapping table,如果没有则可以添加映射表,在进行创建位图索引:
SQL> 
SQL> 
SQL> 
SQL> create table emp_list(
  2  emp_id number(6) not null,
  3  first_name varchar2(20)
  4  ,last_name varchar2(20),
  5  email varchar2(25) not null,
  6  constraint emp_list_pk primary key (emp_id,first_name)
  7  )
  8  organization index
  9  mapping table;

Table created.

SQL> create bitmap index emp_list_btidx1 on emp_list(email) nologging;

Index created.

SQL> drop index emp_list_btidx1;

Index dropped.

SQL> alter table emp_list move nomapping; 

Table altered.

SQL> create bitmap index emp_list_btidx1 on emp_list(email) nologging;
create bitmap index emp_list_btidx1 on emp_list(email) nologging
                                       *
ERROR at line 1:
ORA-28669: bitmap index can not be created on an IOT with no mapping table


SQL> alter table emp_list move mapping table;

Table altered.


SQL> create bitmap index emp_list_btidx1 on emp_list(email) nologging;

Index created.

SQL> 

另外在使用星型模式时,位图索引可以提高很高的性能,但是在中心事实表的外键列上必须创建位图索引,另外还需要配置星型转换参数如:star_transformation_enabled 为true;
如果没有走星型转换可以强制添加hint(提示)如:/*+star_transformation*/ /*+star_transformation fact(column_name)*/
在 开始也提到位图索引对dml语句支持性不好,因此在搞的dml操作的时候需要对位图索引进行unusable之后再重建。对于分区位图索引需要对每个分区进行位图索引重建;
如:alter index xxxx modify partition ppppppp unusable; alter index xxxx rebuild partition ppppppp;或是对分区上所有索引重建:alter table xxx modify partition xxxx rebuild unusable local indexes;

另外对于位图索引还有一个位图连接索引
位图连接索引适合与星型模式,就是一个大的事实表与维度表之间的连接列的物化连接,在创建连接索引过程中就已经完成了连接位置操作,连接的结果也存在于连接索引中,因此连接查询速度会更高:
创建实例如下

create bitmap index emp_bjix01
on xxx(a.ssss,b.dddd)
from www a,zzz b
where a.pp=b.pp
tablespace mmmmm
pctfree 5
parallel 4
l