当对分区表进行 一些操作时,会造成索引失效。
当有truncate/drop/exchange 操作分区 时全局索引 会失效。
exchange 的临时表没有索引,或者
有索引,没有用including indexes的关键字,会导致局部的索引失效,就是某个分区失效重建局部索引只能用alter index local_idx rebuild partition p1这样的方式分区表SPLIT的时候,如果MAX区中已经有记录了,这个时候SPLIT就会导致有记录的新增分区的局部索引失效!
查寻某个分区表中 各个分区 索引状态 USABLE/UNUSABLE
select index_name, partition_name, status from user_ind_partitions where index_name = 'indexName';
--重建索引
--local索引重建select b.table_name,a.INDEX_NAME,a.PARTITION_NAME,a.STATUS,'alter index ' || a.index_name || ' rebuild partition ' ||partition_name || ';' 重建列from USER_IND_PARTITIONS a, user_part_indexes bwhere a.index_name = b.index_nameand b.TABLE_NAME IN ('PART_TAB_SPLIT')and STATUS = 'UNUSABLE'ORDER BY b.table_name, a.INDEX_NAME, a.PARTITION_NAME;--全局索引重建 alter index idx_part_split_col3 rebuild;
在针对truncate等 操作时直接更新 index 也可以搞定。
alter table part_tab_trunc truncate partition p2 Update GLOBAL indexes;