分区表及分区索引(16)--增加和删除索引分区
2011-11-02 10:58
537 查看
全面学习分区表及分区索引(16)--增加和删除索引分区
从本节开始,介绍索引分区的管理操作~~
1、增加索引分区(Adding Index Partitions)
从语法上来讲,增加索引分区与增加表分区没有什么实际性差别,将table换成index即可:
Alter index idxname add partition ptname tbs_clause;
需要注意一点add partition只能用于hash的global索引(如果你想为range类型的索引增加分区,不要用add,split也许能帮你实际你的需求),并且add partition无法新增local索引分区,因为local分区是由索引所在基表来维护的。
下面举个操作的例子,还记的我们前面演示创建hash分区的时候创建的索引吗,这里就以它为例吧:
SQL> select partition_name ,tablespace_name from user_ind_partitions
2 where index_name = 'IDX_PART_HASH_ID';
PARTITION_NAME TABLESPACE_NAME
------------------------------ ------------------------------
T_HASH_P1 PART01
T_HASH_P2 PART02
T_HASH_P3 PART03
SQL> alter index idx_part_hash_id add partition i_hash_p4 tablespace part04;
alter index idx_part_hash_id add partition i_hash_p4 tablespace part04
ORA-14076: 提交的变更索引分区/子分区操作对本地分区的索引无效
为什么呢??????????????????????????
####################################################
ORA-14076: DROP/SPLIT PARTITION may not be applied to a LOCAL index partition
Cause: An attempt was made to drop or split a partition of a LOCAL index.
Action: Ensure that the index named in the DROP/SPLIT PARTITION statement is a GLOBAL partitioned index.
####################################################
SQL> select index_name ,table_name ,PARTITIONED,GLOBAL_STATS
2 from user_indexes
3 where index_name ='IDX_PART_HASH_ID';
INDEX_NAME TABLE_NAME PARTITIONED GLOBAL_STATS
------------------------------ ------------------------------ ----------- ------------
IDX_PART_HASH_ID T_PART_HASH YES NO
//SO...这就是原因!!!
之前提到过,add partition只能用于hash的global索引!
SQL> drop index idx_part_hash_id;
Index dropped
//重建 HASH GLOBAL INDEX !(注意:global hash index 是10G新添加的,以前只有global range index!U KNOW THAT!)
SQL> create index idx_part_hash_id on t_part_hash(id)
2 global partition by hash(id)
3 partitions 3 store in (part01,part02,part03);
Index created
SQL> select index_name ,partition_name ,tablespace_name
2 from dba_ind_partitions
3 where index_name = 'IDX_PART_HASH_ID';
INDEX_NAME PARTITION_NAME TABLESPACE_NAME
------------------------------ ------------------------------ ------------------------------
IDX_PART_HASH_ID SYS_P84 PART01
IDX_PART_HASH_ID SYS_P85 PART02
IDX_PART_HASH_ID SYS_P86 PART03
//继续给GLOBAL分区索引添加 分区。
SQL> alter index idx_part_hash_id add partition i_hash_4 tablespace karl_space;
Index altered //OK!
SQL> select index_name ,partition_name,tablespace_name
2 from dba_ind_partitions
3 where index_name ='IDX_PART_HASH_ID';
INDEX_NAME PARTITION_NAME TABLESPACE_NAME
------------------------------ ------------------------------ ------------------------------
IDX_PART_HASH_ID I_HASH_4 KARL_SPACE
IDX_PART_HASH_ID SYS_P84 PART01
IDX_PART_HASH_ID SYS_P85 PART02
IDX_PART_HASH_ID SYS_P86 PART03
2、删除索引分区(Dropping Index Partitions)
Drop partition只能操作global索引的range分区(??????是这样吗?不能操作global的HASH分区?),语法也很简单:
Alter index idxname drop partition ptname;
看起来很简单对吧,但是,需要注意,索引必须拥有一个maxvalue的分区,该分区无法删除。
另外,如果删除的索引分区中包含数据,分区被删除后,会造成相邻的higher分区失效,需要手工编译!这个其实很容易理解,索引中数据都是经过排序的,我们drop partition删除的只是分区,但其对应的索引数据还需要有地儿存在行啊(不然索引启不就不准确了),于是就只好存储到比它更高区间值的索引区分里去了,那个分区莫名其妙多了数据,自然状态就为不可用了。
举个例子:
SQL> select table_owner,table_name,partition_name,high_value,tablespace_name
2 from dba_tab_partitions
3 where table_name = 'T_PART_RANGE';
TABLE_OWNER TABLE_NAME PARTITION_NAME HIGH_VALUE TABLESPACE_NAME
------------------------------ ------------------------------ ------------------------------ ------------------ ------------------------------
KARL T_PART_RANGE T_RANGE_MAX MAXVALUE PART03
KARL T_PART_RANGE T_RANGE_P1 10 PART01
KARL T_PART_RANGE T_RANGE_P2 20 PART02
SQL> create index idx_part_range_id on t_part_range(id)
2 global partition by range(id)(
3 partition i_p1 values less than(10) tablespace part01,
4 partition i_p2 values less than(20) tablespace part02,
5 partition i_max values less than(maxvalue) tablespace part03);
Index created
//即将删除索引分区2
SQL> select * from t_part_range partition(t_range_p2);
ID NAME
---------- ----------
11 afad
12 asdfasd
SQL> alter index idx_part_range_id drop partition i_p2;
Index altered
SQL> select index_name ,partition_name,high_value,status ,tablespace_name
2 from dba_ind_partitions
3 where index_Name = 'IDX_PART_RANGE_ID';
INDEX_NAME PARTITION_NAME HIGH_VALUE STATUS TABLESPACE_NAME
------------------------------ ------------------------------ ----------------- -------- ------------------------------
IDX_PART_RANGE_ID I_MAX MAXVALUE UNUSABLE //失效! PART03
IDX_PART_RANGE_ID I_P1 10 USABLE PART01
于是,i_p1 分区就unusable了,继续往下看吧,后面要讲如何重编译索引分区了。
从本节开始,介绍索引分区的管理操作~~
1、增加索引分区(Adding Index Partitions)
从语法上来讲,增加索引分区与增加表分区没有什么实际性差别,将table换成index即可:
Alter index idxname add partition ptname tbs_clause;
需要注意一点add partition只能用于hash的global索引(如果你想为range类型的索引增加分区,不要用add,split也许能帮你实际你的需求),并且add partition无法新增local索引分区,因为local分区是由索引所在基表来维护的。
下面举个操作的例子,还记的我们前面演示创建hash分区的时候创建的索引吗,这里就以它为例吧:
SQL> select partition_name ,tablespace_name from user_ind_partitions
2 where index_name = 'IDX_PART_HASH_ID';
PARTITION_NAME TABLESPACE_NAME
------------------------------ ------------------------------
T_HASH_P1 PART01
T_HASH_P2 PART02
T_HASH_P3 PART03
SQL> alter index idx_part_hash_id add partition i_hash_p4 tablespace part04;
alter index idx_part_hash_id add partition i_hash_p4 tablespace part04
ORA-14076: 提交的变更索引分区/子分区操作对本地分区的索引无效
为什么呢??????????????????????????
####################################################
ORA-14076: DROP/SPLIT PARTITION may not be applied to a LOCAL index partition
Cause: An attempt was made to drop or split a partition of a LOCAL index.
Action: Ensure that the index named in the DROP/SPLIT PARTITION statement is a GLOBAL partitioned index.
####################################################
SQL> select index_name ,table_name ,PARTITIONED,GLOBAL_STATS
2 from user_indexes
3 where index_name ='IDX_PART_HASH_ID';
INDEX_NAME TABLE_NAME PARTITIONED GLOBAL_STATS
------------------------------ ------------------------------ ----------- ------------
IDX_PART_HASH_ID T_PART_HASH YES NO
//SO...这就是原因!!!
之前提到过,add partition只能用于hash的global索引!
SQL> drop index idx_part_hash_id;
Index dropped
//重建 HASH GLOBAL INDEX !(注意:global hash index 是10G新添加的,以前只有global range index!U KNOW THAT!)
SQL> create index idx_part_hash_id on t_part_hash(id)
2 global partition by hash(id)
3 partitions 3 store in (part01,part02,part03);
Index created
SQL> select index_name ,partition_name ,tablespace_name
2 from dba_ind_partitions
3 where index_name = 'IDX_PART_HASH_ID';
INDEX_NAME PARTITION_NAME TABLESPACE_NAME
------------------------------ ------------------------------ ------------------------------
IDX_PART_HASH_ID SYS_P84 PART01
IDX_PART_HASH_ID SYS_P85 PART02
IDX_PART_HASH_ID SYS_P86 PART03
//继续给GLOBAL分区索引添加 分区。
SQL> alter index idx_part_hash_id add partition i_hash_4 tablespace karl_space;
Index altered //OK!
SQL> select index_name ,partition_name,tablespace_name
2 from dba_ind_partitions
3 where index_name ='IDX_PART_HASH_ID';
INDEX_NAME PARTITION_NAME TABLESPACE_NAME
------------------------------ ------------------------------ ------------------------------
IDX_PART_HASH_ID I_HASH_4 KARL_SPACE
IDX_PART_HASH_ID SYS_P84 PART01
IDX_PART_HASH_ID SYS_P85 PART02
IDX_PART_HASH_ID SYS_P86 PART03
2、删除索引分区(Dropping Index Partitions)
Drop partition只能操作global索引的range分区(??????是这样吗?不能操作global的HASH分区?),语法也很简单:
Alter index idxname drop partition ptname;
看起来很简单对吧,但是,需要注意,索引必须拥有一个maxvalue的分区,该分区无法删除。
另外,如果删除的索引分区中包含数据,分区被删除后,会造成相邻的higher分区失效,需要手工编译!这个其实很容易理解,索引中数据都是经过排序的,我们drop partition删除的只是分区,但其对应的索引数据还需要有地儿存在行啊(不然索引启不就不准确了),于是就只好存储到比它更高区间值的索引区分里去了,那个分区莫名其妙多了数据,自然状态就为不可用了。
举个例子:
SQL> select table_owner,table_name,partition_name,high_value,tablespace_name
2 from dba_tab_partitions
3 where table_name = 'T_PART_RANGE';
TABLE_OWNER TABLE_NAME PARTITION_NAME HIGH_VALUE TABLESPACE_NAME
------------------------------ ------------------------------ ------------------------------ ------------------ ------------------------------
KARL T_PART_RANGE T_RANGE_MAX MAXVALUE PART03
KARL T_PART_RANGE T_RANGE_P1 10 PART01
KARL T_PART_RANGE T_RANGE_P2 20 PART02
SQL> create index idx_part_range_id on t_part_range(id)
2 global partition by range(id)(
3 partition i_p1 values less than(10) tablespace part01,
4 partition i_p2 values less than(20) tablespace part02,
5 partition i_max values less than(maxvalue) tablespace part03);
Index created
//即将删除索引分区2
SQL> select * from t_part_range partition(t_range_p2);
ID NAME
---------- ----------
11 afad
12 asdfasd
SQL> alter index idx_part_range_id drop partition i_p2;
Index altered
SQL> select index_name ,partition_name,high_value,status ,tablespace_name
2 from dba_ind_partitions
3 where index_Name = 'IDX_PART_RANGE_ID';
INDEX_NAME PARTITION_NAME HIGH_VALUE STATUS TABLESPACE_NAME
------------------------------ ------------------------------ ----------------- -------- ------------------------------
IDX_PART_RANGE_ID I_MAX MAXVALUE UNUSABLE //失效! PART03
IDX_PART_RANGE_ID I_P1 10 USABLE PART01
于是,i_p1 分区就unusable了,继续往下看吧,后面要讲如何重编译索引分区了。
相关文章推荐
- 分区表 分区索引 增加 收缩 删除 表分区
- 分区表及分区索引(8)--增加和收缩表分区
- 深入学习分区表及分区索引(8)--增加和收缩表分区
- 分区表及分区索引(9)--删除表分区
- 深入学习分区表及分区索引(9)--删除表分区
- 管理分区表+为范围分区表增加分区+为散列分区表增加分区+为列表分区表增加分区+查看当前用户的表和表分区信息+合并分区+删除分区
- ORACLE分区表、分区索引详解(转)
- MySQL5.5 RANGE分区增加删除处理
- MS SQL Server:分区表、分区索引详解
- MS SQL SERVER 分区表和分区索引(转)
- 11g中的分区表及分区索引
- 分区表及分区索引(6)--创建range-list组合分区
- SQL Server 中的分区表(四):删除(合并)一个分区
- Oracle 分区表增加分区
- MS SQL Server:分区表、分区索引 详解
- oracle 分区表和分区索引
- 深入学习分区表及分区索引(7)--怎样管理-续
- SQL Server 2005中的分区表(四):删除(合并)一个分区
- 海量数据优化_分区索引与删除的关系
- 转:深入学习Oracle分区表及分区索引