本篇文章為大家展示了如何進(jìn)行合并分區(qū)coalesce partition,內(nèi)容簡(jiǎn)明扼要并且容易理解,絕對(duì)能使你眼前一亮,通過(guò)這篇文章的詳細(xì)介紹希望你能有所收獲。
成都創(chuàng)新互聯(lián)公司主營(yíng)蔚縣網(wǎng)站建設(shè)的網(wǎng)絡(luò)公司,主營(yíng)網(wǎng)站建設(shè)方案,重慶APP開(kāi)發(fā),蔚縣h5成都小程序開(kāi)發(fā)搭建,蔚縣網(wǎng)站營(yíng)銷(xiāo)推廣歡迎蔚縣等地區(qū)企業(yè)咨詢
合并分區(qū)(coalesce partition):合并分區(qū)是用來(lái)操作HASH分區(qū)表和hash全局索引的。他會(huì)重新分配刪除的分區(qū)的數(shù)據(jù)到你現(xiàn)有的分區(qū)中。
限制:操作HASH分區(qū)表和hash全局索引,如果對(duì)LIST/RANGE分區(qū)表進(jìn)行合并報(bào)錯(cuò)ORA-14259: 表未被散列方法分區(qū)
全局索引只有RANGE和HASH才有,并且RANGE不能使用合并,同時(shí)也不能對(duì)range分區(qū)進(jìn)行添加分區(qū)報(bào)錯(cuò)ORA-14640: 添加/合并索引分區(qū)操作只對(duì)散列分區(qū)的全局索引有效,
而且建立全局RANGE分區(qū)必須帶有MAXVALUE屬性,并且是不行刪除的MAXVALUE分區(qū),如果刪除報(bào)錯(cuò)ORA-14078: 您不能刪除 GLOBAL 索引的最高分區(qū)。
我們這里討論對(duì)索引的影響,包括全局索引,本地索引和普通索引。
使用腳本:
drop table t_pe_h;
CREATE TABLE t_pe_h (i NUMBER, j NUMBER , f number,k varchar2(20))
PARTITION BY hash(j)
(PARTITION p1 ,
PARTITION p2,
partition p4,
partition p3);
create index t_pe_h_n on t_pe_h(i);
create index t_pe_h_l on t_pe_h(j) local;
create index t_pe_h_g on t_pe_h(f)
GLOBAL PARTITION BY range(f)
(PARTITION p1 VALUES less than (10),
PARTITION p2 VALUES less than (20),
PARTITION p3 VALUES less than (maxvalue ));
insert into t_pe_h
values(2,5,5,'A');
insert into t_pe_h
values(1,15,10,'B');
insert into t_pe_h
values(3,25,40,'C');
insert into t_pe_h
values(2,65,30,'A');
insert into t_pe_h
values(1,75,20,'B');
insert into t_pe_h
values(3,85,50,'C');
select INDEX_NAME ,STATUS,a.partition_name from dba_ind_partitions a where lower(index_name)='t_pe_h_l';
select INDEX_NAME ,STATUS,a.partition_name from dba_ind_partitions a where lower(index_name)='t_pe_h_g';
select INDEX_NAME ,STATUS from dba_indexes where lower(index_name)='t_pe_h_n';
然后查看索引狀態(tài)
SQL> ALTER TABLE t_pe_h
2 COALESCE PARTITION;
Table altered
SQL>
SQL> select INDEX_NAME ,STATUS,a.partition_name from dba_ind_partitions a where lower(index_name)='t_pe_h_l';
INDEX_NAME STATUS PARTITION_NAME
------------------------------ -------- ------------------------------
T_PE_H_L USABLE P4
T_PE_H_L UNUSABLE P2
T_PE_H_L USABLE P1
SQL> select INDEX_NAME ,STATUS,a.partition_name from dba_ind_partitions a where lower(index_name)='t_pe_h_g';
INDEX_NAME STATUS PARTITION_NAME
------------------------------ -------- ------------------------------
T_PE_H_G UNUSABLE P3
T_PE_H_G UNUSABLE P2
T_PE_H_G UNUSABLE P1
SQL> select INDEX_NAME ,STATUS from dba_indexes where lower(index_name)='t_pe_h_n';
INDEX_NAME STATUS
------------------------------ --------
T_PE_H_N UNUSABLE
可以發(fā)現(xiàn)都失效了,明顯的合并分區(qū)自動(dòng)把P2 ,P3合并為P2了,并且起本地索引相關(guān)的P2分區(qū)也失效了,因?yàn)榈讓拥谋淼腞OWID改變了。
普通索引和全局索引均失效。
然后我們?cè)囋嘦PDATE INDEXES
SQL> ALTER TABLE t_pe_h
2 COALESCE PARTITION update indexes;
Table altered
SQL>
SQL> select INDEX_NAME ,STATUS,a.partition_name from dba_ind_partitions a where lower(index_name)='t_pe_h_l';
INDEX_NAME STATUS PARTITION_NAME
------------------------------ -------- ------------------------------
T_PE_H_L USABLE P4
T_PE_H_L USABLE P2
T_PE_H_L USABLE P1
SQL> select INDEX_NAME ,STATUS,a.partition_name from dba_ind_partitions a where lower(index_name)='t_pe_h_g';
INDEX_NAME STATUS PARTITION_NAME
------------------------------ -------- ------------------------------
T_PE_H_G USABLE P3
T_PE_H_G USABLE P2
T_PE_H_G USABLE P1
SQL> select INDEX_NAME ,STATUS from dba_indexes where lower(index_name)='t_pe_h_n';
INDEX_NAME STATUS
------------------------------ --------
T_PE_H_N VALID
可以看到均有效,沒(méi)有問(wèn)題。另外你還可以使用合并分區(qū)來(lái)合并全局HASH的索引,如下:
ALTER INDEX hgidx COALESCE PARTITION;(對(duì)hash全局分區(qū)索引有效)
上述內(nèi)容就是如何進(jìn)行合并分區(qū)coalesce partition,你們學(xué)到知識(shí)或技能了嗎?如果還想學(xué)到更多技能或者豐富自己的知識(shí)儲(chǔ)備,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。