您的位置:首页 > 其它

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

2014-07-09 20:53 435 查看
以下转自:http://blog.chinaunix.net/uid-23284114-id-3421922.html 作者:十字螺丝钉操作分区表对global和local索引的影响 (二)请参考 /article/6950912.html五、truncate partition1.分区含有数据,不加update indexesSQL> 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 USABLEIND_NAME P3 15 USABLEIND_NAME P4 20 USABLE 2.分区含有数据,加update indexesSQL> 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 USABLEIND_NAME P3 15 USABLEIND_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 indexesSQL> 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 USABLEIND_NAME P3 15 USABLEIND_NAME P4 20 USABLEIND_NAME P5 25 UNUSABLEIND_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 USABLEIND_NAME P3 15 USABLEIND_NAME P4 20 USABLEIND_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 USABLEIND_NAME P3 15 USABLEIND_NAME P4 20 USABLEIND_NAME P5 25 USABLEIND_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 MAXVALUEPART_TEST P1 5PART_TEST P3 15PART_TEST P4 20PART_TEST P5 25 p4和p5分区都含有数据,把他们合并为p6分区 1.不加update indexesSQL> 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 USABLEIND_NAME P3 15 USABLEIND_NAME P6 25 UNUSABLEIND_NAME MAX_PART MAXVALUE USABLE 2.加update indexesSQL> 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 USABLEIND_NAME P3 15 USABLEIND_NAME P6 25 USABLEIND_NAME MAX_PART MAXVALUE USABLE 操作分区表对global和local索引的影响 (四)请参考 /article/6950904.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: