索引组织表中的MAPPING TABLE

来源:互联网 发布:阿里云 怎么注销 编辑:程序博客网 时间:2024/06/05 03:04
Oracle supports bitmap indexes on partitioned and nonpartitionedindex-organized tables.A mapping table is required for creatingbitmap indexes on an index-organized table.


The mapping table is a heap-organized table that stores logicalrowids of the index-organized table. Specifically,each mappingtable row stores one logical rowid for the correspondingindex-organized table row. Thus,the mapping table providesone-to-one mapping between logical rowids of the index-organizedtable rows and physical rowids of the mapping table rows.


A bitmap index on an index-organized table is similar to that on aheap-organized table except that the rowids used in the bitmapindex on an index-organized table are those of the mapping table asopposed to the base table. There is one mapping table for eachindex-organized table and it is used by all the bitmap indexescreated on that index-organized table.


In both heap-organized and index-organized base tables, a bitmapindex is accessed using a search key. If the key is found, thebitmap entry is converted to a physical rowid. In the case ofheap-organized tables, this physical rowid is then used to accessthe base table. However, in the case of index-organized tables, thephysical rowid is then used to access the mapping table. The accessto the mapping table yields a logical rowid. This logical rowid isused to access the index-organized table.


Though a bitmap index on an index-organized table does not storelogical rowids, it is still logical in nature.


大意是说:Oracle数据库支持在分区或者不分区的索引组织表(IOT)上创建位图索引。在向索引组织表创建位图索引的时候必须要有MAPPINGTABLE。

MAPPING TABLE是一个HEAP表(即普通表),用来存储索引组织表的逻辑rowid。具体来说,MAPPINGTABLE的每一行存储了一个逻辑rowid,用来关联索引组织表的行。因此,MAPPINGTABLE的物理rowid和索引组织表的行之间产生了一对一的关联。因为索引组织表的rowid会经常变化,所以只有逻辑rowid,而不像普通表的行具有物理rowid,可以直接对应到具体的物理存放地点。在索引组织表上创建的位图索引和在普通HEAP表上创建的位图索引是类似的,只不过如果是索引组织表,那位图索引会使用MAPPINGTABLE的rowid。在查询的时候,2种表都是通过key字段访问,在key字段找到之后,普通HEAP表会直接把key转换成rowid,然后通过rowid定位到具体的数据块中。但是如果是索引组织表,会通过key转换成rowid后,到MAPPINGTABLE中去查找逻辑rowid,然后通过这个逻辑rowid去访问索引组织表里的数据。


SQL> create table t_testmap(eno number primary key,enamevarchar2(10)) organization index;


Table created.


SQL> create bitmap index idx_map on t_testmap(ename);
create bitmap index idx_map on t_testmap(ename)
*
ERROR at line 1:
ORA-28669: bitmap index can not be created on an IOT with nomapping table

无法在没有mapping table的情况下给IOT创建位图索引。


SQL> create table t_testmap2(eno number primary key,enamevarchar2(10)) organization index mapping table;


Table created.


SQL> create bitmap index idx_map on t_testmap2(ename);


Index created.


位图索引创建成功。


SQL> select table_name,iot_name,iot_type from user_tables;


TABLE_NAME IOT_NAME IOT_TYPE
------------------------------ ---------------------------------------------------
SYS_IOT_MAP_10258 T_TESTMAP2 IOT_MAPPING
T_TESTMAP2 IOT
T_TESTMAP IOT

SQL> select index_name, index_type, table_name, uniqueness fromuser_indexes;


INDEX_NAME INDEX_TYPE TABLE_NAME UNIQUENES
------------------------------ --------------------------------------------------------- ------------------
IDX_MAP BITMAP T_TESTMAP2 NONUNIQUE
SYS_IOT_TOP_10258 IOT - TOP T_TESTMAP2 UNIQUE
SYS_IOT_TOP_10256 IOT - TOP T_TESTMAP UNIQUE

这里可以看出索引组织表虽然是表,但是存储的结构是索引


SQL> drop table SYS_IOT_MAP_10258;
drop table SYS_IOT_MAP_10258
*
ERROR at line 1:
ORA-28668: cannot reference mapping table of an index-organizedtable


mapping table 无法被直接删除,但是可以通过move进行删除


SQL> alter table t_testmap2 move nomapping;
alter table t_testmap2 move nomapping
*
ERROR at line 1:
ORA-28670: mapping table cannot be dropped due to an existingbitmap index

在创建了bitmap index的时候,mapping table也无法被删除。


SQL> drop index idx_map;


Index dropped.


SQL> alter table t_testmap2 move nomapping;


Table altered.


SQL> select table_name,iot_name,iot_type from user_tables;


TABLE_NAME IOT_NAME IOT_TYPE
------------------------------ ------------------------------------------
T_TESTMAP2 IOT
T_TESTMAP IOT


这时再查询就发现mapping table被删除了。


SQL> select object_name, original_name, type fromrecyclebin;


no rows selected

而且这种删除不会把mapping table放入回收站。

如果因为误操作等原因想恢复mapping table,可以使用以下命令重建。


SQL> alter table t_testmap move mapping table;


Table altered.


SQL> select table_name,iot_name,iot_type from user_tables;


TABLE_NAME IOT_NAME IOT_TYPE
------------------------------ -------------------------------------------------
SYS_IOT_MAP_10256 T_TESTMAP IOT_MAPPING
T_TESTMAP2 IOT
T_TESTMAP IOT


此时mapping table又重新创建。


SQL> create bitmap index idx_map on t_testmap(ename);


Index created.

重新创建索引以进行下面的实验。


SQL> drop table t_testmap;


Table dropped.


SQL> select object_name, original_name, type fromrecyclebin;


OBJECT_NAME ORIGINAL_NAME TYPE
------------------------------ ---------------------------------------------------------
BIN$tKX6TiUGBMLgQAB/AQATjQ==$0 IDX_MAP INDEX
BIN$tKX6TiUHBMLgQAB/AQATjQ==$0 SYS_IOT_TOP_10256 IOT TOPINDEX
SYS_IOT_MAP_10256 SYS_IOT_MAP_10256 IOT MAPPING TABLE
BIN$tKX6TiUIBMLgQAB/AQATjQ==$0 T_TESTMAP TABLE


如果直接删除表t_testmap,那么该索引组织表上关联的mapping table 和 bitmap index会一起被放入回收站中。


SQL> flashback table t_testmap to before drop;


Flashback complete.


SQL> select table_name,iot_name,iot_type from user_tables;


TABLE_NAME IOT_NAME IOT_TYPE
------------------------------ ------------------------------------------
SYS_IOT_MAP_10256 T_TESTMAP IOT_MAPPING
T_TESTMAP IOT
T_TESTMAP2 IOT


SQL> select index_name, index_type, table_name fromuser_indexes;


INDEX_NAME INDEX_TYPE TABLE_NAME
------------------------------ -------- -------------------------------------------------
BIN$tKX6TiUGBMLgQAB/AQATjQ==$0  BITMAP       T_TESTMAP
BIN$tKX6TiUHBMLgQAB/AQATjQ==$0  IOT -TOP    T_TESTMAP
SYS_IOT_TOP_10258                          IOT -TOP     T_TESTMAP2

原创粉丝点击