Oracle分区表的维护和索引的相关注意事项

教程发布:风哥 教程分类:ITPUX技术网 更新日期:2022-02-12 浏览学习:237

[size=21pt]Oracle[size=21pt]分区表的维护和索引的相关注意事项

[color=#0800]1、分区表索引重建[color=#0800]rebuild index
-------------------------------
对于分区索引,不能整体进行重建,只能对单个分区进行重建(也就是物理存在的分区)。语法如下:
Alter index idx_name rebuild partition index_partition_name [online nologging]
Alter Index Index1 Rebuild Partition Sys_P21;

有子分区的本地索引,不能重建某分区,只能对每个子分区进行重建
Alter Index Index2 Rebuild subPartition P_20100205_GROT;

重建不可用的索引脚本,重建所有unUsable的索引
[color=#08080]Select[color=#0080] 'alter index '[color=#0080] || Index_Name || ' rebuild;'
[color=#0080] [color=#08080]From[color=#0080] User_Indexes
[color=#0080][color=#08080]Where[color=#0080] Status = 'UNUSABLE'
[color=#08080]union
[color=#08080]Select[color=#0080] 'alter index '[color=#0080] || Index_Name || ' rebuild Partition '[color=#0080] ||
[color=#0080] Partition_Name || ';'
[color=#0080] [color=#08080]From[color=#0080] User_Ind_Partitions
[color=#0080][color=#08080]Where[color=#0080] Status = 'UNUSABLE'
[color=#08080]union
[color=#08080]Select[color=#0080] 'alter index '[color=#0080] || Index_Name || ' rebuild subPartition '[color=#0080] ||
[color=#0080] subPartition_Name || ';'
[color=#0080] [color=#08080]From[color=#0080] User_Ind_subPartitions
[color=#0080][color=#08080]Where[color=#0080] Status = 'UNUSABLE'[color=#0080];

add parttion
----------------------------------------------------------------------------------------------------------------------
Alter Table Test_Tab1 Add Partition P_20100730 Values Less Than (20100801);

1 如果有子分区,且定义了子分区模板,所有的子分区会自动添加
2 新加分区后,该区没有统计信息,全是空,如果表级不是global_satus,则表级的统计信息也会空
3. 新加分区后,如果表级统计是global_satus,还会出现out of range的问题(CBO估算的选择率很低)
4 解决2,3问题的方法是:copy_table_stats

exec dbms_stats.copy_table_stats(user, tabname => 'TEST_TAB1', srcpartname =>'P_20100206', dstpartname => 'P_20100207');

[color=#0800]2、删除分区表[color=#0800]tuncate and drop partition
------------------------------------------------------------------------------------------------------

truncate和drop可对有子分区的分区进行
ALTER TABLE TEST_TAB1 truncate Partition P_20100730;
ALTER TABLE TEST_TAB1 Drop Partition P_20100730;

它们会导致globl index的某些分区不可用,必须这样做
ALTER TABLE TEST_TAB1 truncate Partition P_20100730 update indexes;
ALTER TABLE TEST_TAB1 truncate Partition P_20100730 update global indexes;
ALTER TABLE TEST_TAB1 Drop Partition P_20100730 update indexes;
ALTER TABLE TEST_TAB1 Drop Partition P_20100730 update global indexes;

move partition
-------------------------------------------------------------------------------------------------------------------

有子分区的分区不能move,只能move每个子分区(也就是物理分区)
Alter Table Test_Tab1 Move Partition P_20100730; --报错,有子分区,只是一个逻辑分区

由于rowid变了,会导致所有相关索引unusable,必须这样做
Alter Table Test_Tab1 Move subPartition P_20100730_GROT update indexes;
Alter Table Test_Tab1 Move subPartition P_20100730_GROT update global indexes;
--Local Index没有更新

[color=#0800]3、分离分区[color=#0800]split partion
------------------------------------------------------------------------------------------------------------------

语法:
alter table split partition at ()
into (partition , partition )
[update [global] indexes];

1 可以对有子分区的分区进行,自动split子分区
2 由于rowid变了,新分区和global index都变为unusable

eg:
Alter Table Test_Tab1
Split Partition P_20100730 At (20100715)
into (Partition P_20100715, Partition P_20100731);

[color=#0800]4、[color=#0800]合并分区
------------------------------------------------------------------------------------------------------------------------------------
语法比较复杂,不同的分区不一样

合并range分区
ALTER TABLE Test_Tab1
Merge Partitions P_20100715, P_20100731 Into Partition P_20100730
[Update [global] Indexes];

1. 该分区有子分区
2. 有子分区,也可以单独合并子分区merge subpartition
3. global index是好的,但local index有问题,rowid会变化的都要用update indexes

本文标签:
网站声明:本文由风哥整理发布,转载请保留此段声明,本站所有内容将不对其使用后果做任何承诺,请读者谨慎使用!
【上一篇】
【下一篇】