Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1282126
  • 博文数量: 127
  • 博客积分: 2286
  • 博客等级: 大尉
  • 技术积分: 1943
  • 用 户 组: 普通用户
  • 注册时间: 2010-06-10 10:37
文章分类

全部博文(127)

文章存档

2018年(1)

2015年(2)

2014年(1)

2013年(30)

2012年(88)

2011年(5)

分类: Oracle

2012-08-10 17:17:23

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的索引
Select 'alter index ' || Index_Name ||' rebuild;' From User_Indexes Where Status ='UNUSABLE' union
Select 'alter index ' || Index_Name ||' rebuild Partition '||Partition_Name ||';' From User_Ind_Partitions Where Status ='UNUSABLE' union
Select 'alter index ' || Index_Name ||' rebuild subPartition '||subPartition_Name ||';' From User_Ind_subPartitions Where Status ='UNUSABLE';


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');


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没有更新

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);

合并分区
------------------------------------------------------------------------------------------------------------------------------------
语法比较复杂,不同的分区不一样

合并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


阅读(2338) | 评论(0) | 转发(2) |
给主人留下些什么吧!~~