日期:2014-05-16  浏览次数:20500 次

索引分区:全局索引和本地索引一些备忘

最近公司做一些分析报表,某两个表一个月的记录量去到1亿,因是同事负责,自己没能接触,但同事问起,一时想到使用分区表一技术,故再仔细的研究了一下,以下为备忘:

?

全局索引(global index)

1.必须是前缀索引,即索引列必须是以索引分区键作为前列,测试如下:

SQL> create table t4

? 2 ?(bp varchar2(10),

? 3 ? tdate date)

? 4 ? partition by range(tdate)

? 5 ?(partition p1 values less than (to_date('20120101','yyyymmdd')),

? 6 ? partition p2 values less than (to_date('20130101','yyyymmdd')),

? 7 ? partition pmax values less than (maxvalue));

?

SQL> create index t4_idx1 on t4(bp)

? 2 ?global partition by range(bp)

? 3 ?(partition p1 values less than ('999999999'),

? 4 ? partition p2 values less than (maxvalue));

?

Index created.

?

SQL> create index t4_idx2 on t4(bp)

? 2 ?global partition by range(area) ?

? 3 ?(partition p1 values less than (to_date('20120101','yyyymmdd')),

? 4 ? partition p2 values less than (maxvalue));

global partition by range(area)

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? *

ERROR at line 2:

ORA-14038: GLOBAL partitioned index must be prefixed

?

2.若要分区的话只能按range或hash分区(hash分区是10g后才支持)

3.因全局索引的分区不依赖分区表,故表的分区更改后,须手动rebuild索引分区以作同步,该步操作消耗资源较大.

? ? ? ? ?1)查找失效的partition

? ? ? ? ? select index_name,partition_name,status from dba_ind_partitions where status='UNUSABLE';

? ? ? ? ?2)只能单个分区rebuild.

? ? ? ? ?alter table <table> rebuild parition <partition name>

本地索引(local index)

1.唯一性的本地分区索引须含表分区键列,测试如下: