此处只说索引失效的场景(只会影响全局索引): 结论:全局索引truncate 分区和交换分区都会导致索引失效果 局部索引truncate分区不会导致索引失效。
drop table part_tab_trunc purge; create table part_tab_trunc (id int,col2 int,col3 int,contents varchar2(4000)) partition by range (id) ( partition p1 values less than (10000), partition p2 values less than (20000), partition p3 values less than (maxvalue) ) ; insert into part_tab_trunc select rownum ,rownum+1,rownum+2, rpad('*',400,'*') from dual connect by rownum <=50000; commit; create index idx_part_trunc_col2 on part_tab_trunc(col2) local; create index idx_part_trunc_col3 on part_tab_trunc(col3) ; ---分区truncate前 select index_name, partition_name, status from user_ind_partitions where index_name = 'IDX_PART_TRUNC_COL2'; INDEX_NAME PARTITION_NAME STATUS ------------------------------ ------------------------------ -------- IDX_PART_TRUNC_COL2 P1 USABLE IDX_PART_TRUNC_COL2 P2 USABLE IDX_PART_TRUNC_COL2 P3 USABLE select index_name, status from user_indexes where index_name = 'IDX_PART_TRUNC_COL3'; INDEX_NAME STATUS ------------------------------ -------- IDX_PART_TRUNC_COL3 VALID alter table part_tab_trunc truncate partition p1 ; ---分区truncate后 select index_name, partition_name, status from user_ind_partitions where index_name = 'IDX_PART_TRUNC_COL2'; INDEX_NAME PARTITION_NAME STATUS ------------------------------ ------------------------------ -------- IDX_PART_TRUNC_COL2 P1 USABLE IDX_PART_TRUNC_COL2 P2 USABLE IDX_PART_TRUNC_COL2 P3 USABLE select index_name, status from user_indexes where index_name = 'IDX_PART_TRUNC_COL3'; INDEX_NAME STATUS ------------------------------ -------- IDX_PART_TRUNC_COL3 UNUSABLE