oracle11.2中分区功能测试之add&split partition对global&local index的影响
生产库中某些大表的分区异常,需要对现有表进行在线操作,以添加丢失分区,因为是生产库,还是谨慎点好,今天有空,针对add&split分区对global&local索引的影响进行了测试,测试版本为oracle11.2.0.4,过程如下:
首先,创建分区表:
CREATE TABLE TP1
(
C1 INT PRIMARY KEY,
C2 VARCHAR2(10),
C3 CHAR(10)
)
partition by range (c1)
(
partition p1 values less than(6),
partition p2 values less than(11),
partition p3 values less than(16),
partition maxvalue values less than(maxvalue));
但在add partition时遇到了问题,报错如下:
ORA-14074: 分区界限必须调整为高于最后一个分区界限
根本原因是存在最后maxvalue分区,于是,再创建一个不带maxvalue的分区表:
CREATE TABLE TP2
(
C1 INT PRIMARY KEY,
C2 VARCHAR2(10),
C3 CHAR(10)
)
partition by range (c1)
(
partition p1 values less than(6),
partition p2 values less than(11),
partition p3 values less than(16));
然后,创建local索引:
create index idx_tp2_c2 on tp2(c2) local;
因为主键就是个global索引,所以,不需要另外创建global index,我们insert数据:
insert into tp2 values(1,'aaa','aaa');
insert into tp2 values(2,'aaa','aaa');
insert into tp2 values(3,'aaa','aaa');
insert into tp2 values(4,'aaa','aaa');
insert into tp2 values(5,'aaa','aaa');
insert into tp2 values(6,'aaa','aaa');
insert into tp2 values(7,'aaa','aaa');
insert into tp2 values(8,'aaa','aaa');
insert into tp2 values(9,'aaa','aaa');
insert into tp2 values(10,'aaa','aaa');
insert into tp2 values(11,'aaa','aaa');
insert into tp2 values(12,'aaa','aaa');
insert into tp2 values(13,'aaa','aaa');
insert into tp2 values(14,'aaa','aaa');
insert into tp2 values(15,'aaa','aaa');
commit;
我们add partition:
ALTER TABLE tp2 add PARTITION p10 values less than(51);
add partition成功,因为不存在maxvalue分区。检查主键和索引:
select index_name,status from user_indexes where table_name='TP2';
select index_name,partition_name,status from user_ind_partitions where index_name='IDX_TP2_C2' order by partition_name;
经检查,add partition对global和local索引均无影响,如下图:
那么,split partition:
ALTER TABLE tp2 SPLIT PARTITION p1 AT (3) INTO (PARTITION p1, PARTITION p13);
发现split分区会导致golbal索引不可用,而local索引的相应分区也不可用,如下图:
重建主键索引:
ALTER INDEX SYS_C0027745 REBUILD ONLINE;
重建主键索引后,global索引及local索引状态如下:
为split分区命令添加update indexes选项:
ALTER TABLE tp2 SPLIT PARTITION p2 AT (8) INTO (PARTITION p2, PARTITION p28) update indexes;
检查本次split分区对global&local索引均无影响,如下图:
rebuild local索引不可用的分区:
alter index idx_tp2_c2 rebuild partition p1 online;
alter index idx_tp2_c2 rebuild partition p13 online;
检查local索引状态如下:
以上为测试过程和结果,记录于此,以便今后其他同学和自己参考。
----------------------------------------------------------
《高性能SQL调优精要与案例解析》
blog1:http://www.cnblogs.com/lhdz_bj
blog2:http://blog.itpub.net/8484829
blog3:http://blog.csdn.net/tuning_optmization