分區交換 alter table exchange partition 在線表 歷史表交換

創建表test_part_1 默認爲users表空間:

create table test_part_1(a number, b number)

partition by range(a)

(

  partition p1 values less than (10),

  partition p2 values less than (20),

  partition p3 values less than (30),

  partition p4 values less than (40)

);

創建test_part_1 本地索引

create index idx_id on test_part_1(a) local tablespace TS_KSZIP_BASE;

--插入記錄

insert into test_part_1 values(1,2);

insert into test_part_1 values(11,2);

insert into test_part_1 values(21,2);

insert into test_part_1 values(31,2);

commit;

--查看記錄

select rowid from test_part_1 where a=1;--AAAlz4AAEAAFTUEAAA  查詢1


--創建中間表

create table test_part_3(a number, b number);

create index idx_id3 on test_part_3(a);--默認表空間users


--test_part_1 與中間表交換

alter table test_part_1 exchange partition p1 with table test_part_3 including indexes with validation; --目標表有數據不能交換,交換隻能是分區和非分區表交換

--驗證

select * from dba_ind_partitions where index_name=upper('idx_id');--p1的表空間變成了users,並且狀態爲usable,不用rebuild

select * from dba_indexes where index_name=upper('idx_id3');--表空間變成了TS_KSZIP_BASE.

select rowid from test_part_3;--AAAlz4AAEAAFTUEAAA 跟查詢1對比可見 只是改了數據字典

--創建 目標分區表test_part_2

create table test_part_2(a number, b number)

partition by range(a)

(

  partition p1 values less than (10),

  partition p2 values less than (20),

  partition p3 values less than (30),

  partition p4 values less than (40),

  partition p5 values less than (50)

);

create index idx_id2 on test_part_2(a) local tablespace TS_KSZIP_BASE;

alter table test_part_2 exchange partition p1 with table test_part_3 including indexes with validation; --目標表有數據不能交換,交換隻能是分區非分區交換

select * from dba_ind_partitions where index_name=upper('idx_id2');--索引p1可用,表空間依然是TS_KSZIP_BASE(因爲此時 idx_id3表空間爲TS_KSZIP_BASE)

select * from dba_indexes where index_name=upper('idx_id3');--表空間爲TS_KSZIP_BASE,狀態也是usable



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章