较大的分区表在创建索引的时候是一件非常痛苦的事情,执行过程很漫长,会使用大量的资源。到新的工作地点后,数据治理的同事给了一个非常好的案例,首先创建一个unusable的索引,这样索引定义非常快速的被创建完毕,然后针对unusable状态的分区挨个进行重建,这种操作相比直接创建分区索引较为高效,下面演示案例
1.创建测试表
CREATE TABLE t(id int,name varchar2(20)) PARTITION BY RANGE (id) (PARTITION p1 VALUES LESS THAN (10), PARTITION p2 VALUES LESS THAN (20), PARTITION p3 VALUES LESS THAN (30), PARTITION p4 VALUES LESS THAN (40) );
2.插入数据
begin for i in 1 .. 39 loop insert into t values(i,'andyi'||i); end loop ; commit; end; /
3.创建不可用索引
create index t_1 on t(id) local unusable; alter index t_1 unusable;
4.使用一下语句对分区进行语句构建
#以下SQL是专门搞数据治理的同事给的
set lines 200 pages 200 col table_name for a25 col create_sql for a120 select b.table_name, 'alter index ' || t.index_owner ||'.'|| t.index_name || ' rebuild partition ' || partition_name || ' parallel(degree 16) ' || ' tablespace ' || replace(t.tablespace_name, 'D_', 'I_') || ' nologging;' create_sql from dba_ind_partitions t, dba_indexes b where t.index_name = b.index_name and t.status = 'UNUSABLE' AND T.INDEX_OWNER = b.owner order by b.table_name, partition_name;
TABLE_NAME CREATE_SQL
------------------------- ------------------------------------------------------------------------------------------------------------------------
T alter index DBMON.T_1 rebuild partition P1 parallel(degree 16) tablespace USERS nologging;
T alter index DBMON.T_1 rebuild partition P2 parallel(degree 16) tablespace USERS nologging;
T alter index DBMON.T_1 rebuild partition P3 parallel(degree 16) tablespace USERS nologging;
T alter index DBMON.T_1 rebuild partition P4 parallel(degree 16) tablespace USERS nologging;
标签:index,name,创建,分区,partition,索引,tablespace,alter From: https://www.cnblogs.com/hanglinux/p/16758665.html