操作分区表对global和local索引的影响 (三)

以下转自:http://blog.chinaunix.net/uid-23284114-id-3421922.html 作者:十字螺丝钉

操作分区表对global和local索引的影响 (二)请参考 http://bfc99.blog.51cto.com/265386/1436443

五、truncate partition

1.分区含有数据,不加update indexes

SQL> alter table part_test truncate partition p3;

 

Table truncated.

 

global索引失效不可用

SQL>  select INDEX_NAME,TABLE_OWNER,STATUS from dba_indexes where index_name='IND_ID';

 

INDEX_NAME                                                TABLE_OWNER                                   STATUS

------------------------------ ------------------------------ --------

IND_ID                                                         DOWNLOAD                                       UNUSABLE

 

 

local索引依然可用

SQL> select INDEX_NAME,PARTITION_NAME,HIGH_VALUE,STATUS from dba_ind_partitions where INDEX_NAME='IND_NAME';

 

INDEX_NAME                                                PARTITION_NAME                               HIGH_VALUE                                                                                                                                                   STATUS

------------------------------ ------------------------------ -------------------------------------------------------------------------------- --------

IND_NAME                               P1                                                      5                                                                                                                                                                    USABLE

IND_NAME                              P3                                                      15                                                                                                                                                                   USABLE

IND_NAME                               P4                                                      20                                                                                                                                                                   USABLE

 

 

2.分区含有数据,加update indexes

SQL> insert into part_test values(11,'lucy');  --落在p3分区

 

1 row created.

 

SQL> commit;

 

Commit complete.

 

重建global索引

SQL> alter index IND_ID rebuild;

 

Index altered.

 

 

SQL> alter table part_test truncate partition p3 update indexes;

 

Table truncated.

 

 

加上update indexes后,global索引不再失效。

SQL> select INDEX_NAME,TABLE_OWNER,STATUS from dba_indexes where index_name='IND_ID';

 

INDEX_NAME                                                TABLE_OWNER                                   STATUS

------------------------------ ------------------------------ --------

IND_ID                                                         DOWNLOAD                                       VALID

 

SQL>  select INDEX_NAME,PARTITION_NAME,HIGH_VALUE,STATUS from dba_ind_partitions where INDEX_NAME='IND_NAME';

 

INDEX_NAME                                                PARTITION_NAME                               HIGH_VALUE                                                                                                                                                   STATUS

------------------------------ ------------------------------ -------------------------------------------------------------------------------- --------

IND_NAME                               P1                                                      5                                                                                                                                                                    USABLE

IND_NAME                               P3                                                      15                                                                                                                                                                   USABLE

IND_NAME                               P4                                                      20                                                                                                                                                                   USABLE

 

小结:分区表中含有数据,truncate partition会造成global索引失效;truncate partition加上update indexes可用避免这种情况。

 

 

六、SPLIT PARTITION(一个分区分裂为多个分区)

准备实验分区

 

SQL> alter table part_test add partition max_part values less than(maxvalue);

 

Table altered.

 

SQL> insert into part_test values(21,'john');

 

1 row created.

 

SQL>  insert into part_test values(30,'dog');

 

1 row created.

 

SQL> commit;

 

Commit complete.

 

 

SQL>  select * from part_test partition(MAX_PART);

 

                    ID NAME

---------- ----------

                    21 john

                    30 dog

 

 

1.不加update indexes

SQL> alter table part_test split partition max_part at (25) into (partition p5,partition max_part );

 

Table altered.

 

global索引不可用

SQL>  select INDEX_NAME,TABLE_OWNER,STATUS from dba_indexes where index_name='IND_ID';

 

INDEX_NAME                                                TABLE_OWNER                                   STATUS

------------------------------ ------------------------------ --------

IND_ID                                                         DOWNLOAD                                       UNUSABLE

 

 

local索引,原分区和分裂出的新分区都不可用。

SQL> select INDEX_NAME,PARTITION_NAME,HIGH_VALUE,STATUS from dba_ind_partitions where INDEX_NAME='IND_NAME';

 

INDEX_NAME                                                PARTITION_NAME                               HIGH_VALUE                                                                                                                                                   STATUS

------------------------------ ------------------------------ -------------------------------------------------------------------------------- --------

IND_NAME                               P1                                                      5                                                                                                                                                                    USABLE

IND_NAME                               P3                                                      15                                                                                                                                                                   USABLE

IND_NAME                               P4                                                      20                                                                                                                                                                   USABLE

IND_NAME                               P5                                                      25                                                                                                                                                                   UNUSABLE

IND_NAME                               MAX_PART                                         MAXVALUE                                                                                                                                                                           UNUSABLE

 

 

2.加update indexes

 

SQL> select INDEX_NAME,PARTITION_NAME,HIGH_VALUE,STATUS from dba_ind_partitions where INDEX_NAME='IND_NAME';

 

INDEX_NAME                                                PARTITION_NAME                               HIGH_VALUE                                                                                                                                                   STATUS

------------------------------ ------------------------------ -------------------------------------------------------------------------------- --------

IND_NAME                               P1                                                      5                                                                                                                                                                     USABLE

IND_NAME                               P3                                                      15                                                                                                                                                                   USABLE

IND_NAME                               P4                                                      20                                                                                                                                                                   USABLE

IND_NAME                               MAX_PART                                         MAXVALUE                                                                                                                                                                           USABLE

 

SQL> alter table part_test split partition max_part at (25) into (partition p5,partition max_part ) update indexes;

 

Table altered.

 

加update indexes后,分裂不会造成索引失效。

SQL> select INDEX_NAME,TABLE_OWNER,STATUS from dba_indexes where index_name='IND_ID';

 

INDEX_NAME                                                TABLE_OWNER                                   STATUS

------------------------------ ------------------------------ --------

IND_ID                                                         DOWNLOAD                                       VALID

 

SQL>  select INDEX_NAME,PARTITION_NAME,HIGH_VALUE,STATUS from dba_ind_partitions where INDEX_NAME='IND_NAME';

 

INDEX_NAME                                                PARTITION_NAME                               HIGH_VALUE                                                                                                                                                  STATUS

------------------------------ ------------------------------ -------------------------------------------------------------------------------- --------

IND_NAME                               P1                                                      5                                                                                                                                                                    USABLE

IND_NAME                               P3                                                      15                                                                                                                                                                   USABLE

IND_NAME                               P4                                                      20                                                                                                                                                                   USABLE

IND_NAME                               P5                                                      25                                                                                                                                                                   USABLE

IND_NAME                               MAX_PART                                         MAXVALUE                                                                                                                                                                           USABLE

 

小结:split partition操作,会使global索引和local索引的原分区和分裂出的新分区都不可用。加上update indexes解决这个问题。

 

 

 

七、merge partition(合并分区)

现有分区

SQL>  select table_name,partition_name,HIGH_VALUE from dba_tab_partitions where table_name='PART_TEST' order by  PARTITION_NAME;

 

TABLE_NAME                                                PARTITION_NAME                               HIGH_VALUE

------------------------------ ------------------------------ --------------------------------------------------------------------------------

PART_TEST                               MAX_PART                                         MAXVALUE

PART_TEST                               P1                                                      5

PART_TEST                               P3                                                      15

PART_TEST                               P4                                                      20

PART_TEST                               P5                                                      25

 

 

 

p4和p5分区都含有数据,把他们合并为p6分区

 

1.不加update indexes

SQL>  alter table PART_TEST merge partitions p4,p5 into partition p6;

 

Table altered.

 

 

global索引失效

SQL> select INDEX_NAME,TABLE_OWNER,STATUS from dba_indexes where index_name='IND_ID';

 

INDEX_NAME                                                TABLE_OWNER                                   STATUS

------------------------------ ------------------------------ --------

IND_ID                                                         DOWNLOAD                                       UNUSABLE

 

新生成的分区的索引是失效的。

SQL>  select INDEX_NAME,PARTITION_NAME,HIGH_VALUE,STATUS from dba_ind_partitions where INDEX_NAME='IND_NAME';

 

INDEX_NAME                                                PARTITION_NAME                               HIGH_VALUE                                                                                                                                                   STATUS

------------------------------ ------------------------------ -------------------------------------------------------------------------------- --------

IND_NAME                               P1                                                      5                                                                                                                                                                    USABLE

IND_NAME                               P3                                                      15                                                                                                                                                                   USABLE

IND_NAME                               P6                                                      25                                                                                                                                                                   UNUSABLE

IND_NAME                               MAX_PART                                         MAXVALUE                                                                                                                                                                           USABLE

 

 

2.加update indexes

SQL> alter table PART_TEST merge partitions p4,p5 into partition p6 update indexes;

 

 

Table altered.

 

 

global和local索引都正常。

SQL> SQL>  select INDEX_NAME,TABLE_OWNER,STATUS from dba_indexes where index_name='IND_ID';

 

INDEX_NAME                                                TABLE_OWNER                                   STATUS

------------------------------ ------------------------------ --------

IND_ID                                                         DOWNLOAD                                       VALID

 

SQL>  select INDEX_NAME,PARTITION_NAME,HIGH_VALUE,STATUS from dba_ind_partitions where INDEX_NAME='IND_NAME';

 

INDEX_NAME                                                PARTITION_NAME                               HIGH_VALUE                                                                                                                                                   STATUS

------------------------------ ------------------------------ -------------------------------------------------------------------------------- --------

IND_NAME                               P1                                                      5                                                                                                                                                                    USABLE

IND_NAME                               P3                                                      15                                                                                                                                                                   USABLE

IND_NAME                               P6                                                      25                                                                                                                                                                   USABLE

IND_NAME                               MAX_PART                                         MAXVALUE                                                                                                                                                                           USABLE

 

 

操作分区表对global和local索引的影响 (四)请参考 http://bfc99.blog.51cto.com/265386/1436446

你可能感兴趣的:(索引,本地,全局,影响,分区表操作)