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索引狀態如下:
以上為測試過程和結果,記錄於此,以便今後其他同學和自己參考。
---------------------
作者:lhdz_bj
來源:CSDN
原文:https://blog.csdn.net/tuning_optmization/article/details/45563427
版權宣告:本文為博主原創文章,轉載請附上博文連結!