上一篇文章中我們了解了oracle普通表轉(zhuǎn)化為分區(qū)表的方法的相關(guān)內(nèi)容,接下來的這篇文章,我們將探討oracle分區(qū)索引的失效和重建問題,提供了相關(guān)代碼示例供大家參考,具體如下。
--創(chuàng)建測(cè)試表 SQL> create table t as select object_id,object_name from dba_objects;
表已創(chuàng)建。
SQL> select min(object_id),max(object_id) from t; MIN(OBJECT_ID) MAX(OBJECT_ID) -------------- -------------- 2 76083 SQL> create table t_part(object_id int,object_name varchar2(1000)) partition by range(object_id) 2 ( 3 partition p1 values less than (10000), 4 partition p2 values less than (20000), 5 partition p3 values less than (30000), 6 partition p4 values less than (40000), 7 partition pm values less than (maxvalue));
表已創(chuàng)建。
SQL> insert into t_part select * from t;
已創(chuàng)建72663行。
SQL> commit; --創(chuàng)建本地分區(qū)索引 SQL> create index idx_part_local on t_part(object_name) local;
索引已創(chuàng)建。
創(chuàng)建全局非分區(qū)索引
SQL> create index idx_part_global on t_part(object_id) global;
索引已創(chuàng)建。
刪除其中一個(gè)分區(qū)
SQL> alter table t_part drop partition p1;
表已更改。
全局非分區(qū)索引失效,本地分區(qū)索引沒有失效
SQL> select status,index_name from user_indexes s where index_name='IDX_PART_GLOBAL'; STATUS INDEX_NAME -------- ------------------------------ UNUSABLE IDX_PART_GLOBAL SQL> select status,index_name from user_ind_partitions s where index_name='IDX_PART_LOCAL'; STATUS INDEX_NAME -------- ------------------------------ USABLE IDX_PART_LOCAL USABLE IDX_PART_LOCAL USABLE IDX_PART_LOCAL USABLE IDX_PART_LOCAL --重建失效索引 SQL> alter index idx_part_global rebuild;
索引已更改。
在刪除表分區(qū)的時(shí)候,可以通過以下命令進(jìn)行索引重建
alter table t_part drop partition p2 update indexes;
創(chuàng)建全局分區(qū)索引
SQL> drop index idx_part_global;
索引已刪除。
SQL> CREATE INDEX idx_part_global_full ON t_part (object_id) 2 GLOBAL PARTITION BY RANGE (object_id) 3 (PARTITION p1 VALUES LESS THAN (10000), 4 PARTITION p2 VALUES LESS THAN (30000), 5 PARTITION p3 VALUES LESS THAN (MAXVALUE));
索引已創(chuàng)建。
--刪除其中一個(gè)分區(qū) SQL> alter table t_part drop partition p3;
表已更改。
--全局分區(qū)索引失效 SQL> select status,index_name from user_ind_partitions s where index_name='IDX_PART_GLOBAL_FULL'; STATUS INDEX_NAME -------- ------------------------------ UNUSABLE IDX_PART_GLOBAL_FULL UNUSABLE IDX_PART_GLOBAL_FULL UNUSABLE IDX_PART_GLOBAL_FULL SQL> select /*+index(t IDX_PART_LOCAL)*/ * from t_part t where object_name = '/7f6c264c_IIOPAddress'; OBJECT_ID OBJECT_NAME ---------- ----------------------------------- 35031 /7f6c264c_IIOPAddress 35030 /7f6c264c_IIOPAddress SQL> select /*+index(t IDX_PART_GLOBAL_FULL)*/ * from t_part t where object_id > 35000;
select /*+index(t IDX_PART_GLOBAL_FULL)*/ * from t_part t where object_id > 35000
*
第 1 行出現(xiàn)錯(cuò)誤:
ORA-01502: 索引 'SCOTT.IDX_PART_GLOBAL_FULL' 或這類索引的分區(qū)處于不可用狀態(tài)
當(dāng)需要對(duì)分區(qū)表進(jìn)行下面操作時(shí),都會(huì)導(dǎo)致全局索引的失效。
ADD (HASH) COALESCE (HASH) DROP EXCHANGE MERGE MOVE SPLIT TRUNCATE
之后需要對(duì)失效索引進(jìn)行重建,也可以在刪除分區(qū)表的時(shí)候指定 UPDATE INDEXES 直接進(jìn)行索引的重建。
總結(jié)
以上就是本文關(guān)于oracle分區(qū)索引的失效和重建代碼示例的全部內(nèi)容,希望對(duì)大家有所幫助。感興趣的朋友可以繼續(xù)參閱本站:oracle 數(shù)據(jù)庫啟動(dòng)階段分析、oracle 虛擬專用數(shù)據(jù)庫詳細(xì)介紹等,有什么問題可以直接留言,小編會(huì)及時(shí)回復(fù)大家的。感謝朋友們對(duì)本站的支持!
標(biāo)簽:南充 焦作 郴州 涼山 遼源 滁州 合肥 許昌
巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《oracle分區(qū)索引的失效和重建代碼示例》,本文關(guān)鍵詞 oracle,分區(qū),索引,的,失效,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。