Splitting Partitions 分裂分区

生产环境中,可能碰到由于业务量超出预期,使得某一分区数据过多,导致查询变慢的情况,这时候我们可以通过 Splitting Partitions 语句
对分区表的分区或分区索引 进行分裂,将一个分区变为2个,2个变4个...
以下记录分裂range分区,list分区和hash 分区以及 相应sub_partition 的语法,以备查用。

1、Splitting a Partition of a Range-Partitioned Table
 example
     fee_katy is a partition in the table vet_cats, which has a local index, jaf1. There is also a global index, vet on the table. vet contains two partitions,   vet_parta, and vet_partb.
a、分裂分区
ALTER TABLE vet_cats SPLIT PARTITION
      fee_katy at (100) INTO ( PARTITION
      fee_katy1  [tablspace ts_name1], PARTITION fee_katy2  [tablspace ts_name2]);

如上,分区fee_katy 将分裂成两个全新的分区fee_katy1  和fee_katy2,其数据也会按照分区值对应到相应的分区,原来的fee_katy将不存在。
若不想覆盖原有分区则可以在括号中如此指定:( PARTITION fee_katy1  [tablspace ts_name1], PARTITION fee_katy  [tablspace ts_name2]);
这样,原来的分区fee_katy  依然保留。

b、重建索引
   当对表进行分裂之后全局索引及新的分区的local索引将失效,需要REBUILD
ALTER INDEX JAF1 REBUILD PARTITION fee_katy1;
ALTER INDEX JAF1 REBUILD PARTITION fee_katy2;
ALTER INDEX VET REBUILD PARTITION vet_parta;
ALTER INDEX VET REBUILD PARTITION vet_partb;

2、Splitting a Partition of a List-Partitioned Table
a、The following statement splits the partition region_east into two partitions:

ALTER TABLE sales_by_region
   SPLIT PARTITION region_east VALUES ('CT', 'MA', 'MD')
   INTO
    ( PARTITION region_east_1
         TABLESPACE tbs2,
      PARTITION region_east_2
        STORAGE (INITIAL 8M))
   PARALLEL 5;

b、Splitting a *-List Subpartition
Splitting a list subpartition of a *-list partitioned table is similar to the description in "Splitting a Partition of a List-Partitioned Table", but the syntax is that of SUBPARTITION rather than PARTITION. For example, the following statement splits a subpartition of the quarterly_regional_sales table:

ALTER TABLE quarterly_regional_sales SPLIT SUBPARTITION q2_1999_southwest
   VALUES ('UT') INTO
      ( SUBPARTITION q2_1999_utah
           TABLESPACE ts2,
        SUBPARTITION q2_1999_southwest
           TABLESPACE ts3
      )
   PARALLEL;

3、Splitting a *-Hash Partition
The following example splits a range-hash partition:

ALTER TABLE all_seasons SPLIT PARTITION quarter_1
     AT (TO_DATE('16-dec-1997','dd-mon-yyyy'))
     INTO (PARTITION q1_1997_1 SUBPARTITIONS 4 STORE IN (ts1,ts3),
           PARTITION q1_1997­_2);

 

注意:以上操作完成后注意索引的状态,对失效的local索引及全局索引重建。
 

你可能感兴趣的:(Oralce开发)