转个分区表Local索引Rebuild的总结

今天一个脚本里面的一条build index老是出现ORA-00054: resource busy and acquire with NOWAIT specified 错误,错误本身比较容易理解,肯定是有排他锁限制了对Partition Index的DDL操作。 那么如何避免,以及使用分区索引需要注意的事情,都是需要去总结的,所以下面我结合实验,简单总结一下重建Local Index:

1. DML操作对index partition rebuild的影响。 如果在rebuild某一个分区的时候,有其他的进程在对这个index partition所对应的数据进行DML操作,rebuild会受影响:

kl@k02> create table t_part_1 (a number, b varchar2(10))
2 partition by range(a)
3 (partition t1 values less than (10),
4 partition t2 values less than (20),
5 partition t3 values less than (30),
6 partition tmax values less than (maxvalue));

Table created.

--- 不管是btree index还是bitmap index:
kl@k02> create index t_part_ind1 on t_part_1 (a) local;

Index created.

kl@k02> insert into t_part_1 values (21,'AAA');

1 row created.

< no commit>

--- 然后重新开一个session:
kl@k02> alter index t_part_ind1 rebuild partition t3;
alter index t_part_ind1 rebuild partition t3
*
ERROR at line 1:
ORA-00054: resource busy and acquire with NOWAIT specified

2. 是否考虑加online这个参数,这个参数加上加上以后,除了rebuild过程中index 保持online状态,Oracle还会在rebuild index之前等待所有DML操作结束,然后得到DDL锁,开始rebuild.
kl@k02> alter index t_part_ind1 rebuild partition t3 online;

Index altered.

---- 如果不commit,上面的操作就会一直hold。

3. 如果是bitmap index, online 选项失效
kl@k02> alter index t_part_ind1 rebuild partition t3 online;
alter index t_part_ind1 rebuild partition t3 online
*
ERROR at line 1:
ORA-08108: may not build or rebuild this type of index online

4. 在split以后partition index的状态是usable, 所以split以后不需要重建索引。
5. 在drop 分区 local index的时候,只能drop 整个index; 而rebuild index时只能一个一个分区来drop.
6. 如果Local index失效,在查询时会出现如下问题:
kl@k02> select /*+ full */ * from t_part_1 where a=31;
select /*+ full */ * from t_part_1 where a=31
*
ERROR at line 1:
ORA-01502: index 'KL.T_PART_IND1' or partition of such index is in unusable state

---- 如果走全表扫描,则不会出现:
kl@k02> select /*+ full(t) */ * from t_part_1 t where a=31;

no rows selected

总结: Local Index对查询性能的提高是显而易见的,但他在维护过程中的成本也是比较高的,所以大家在使用Local Index的时候,需要仔细评估一下,如果不经常被使用(比如用MV,代替start-transformation),最好避免使用。

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/628922/viewspace-748487/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/628922/viewspace-748487/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值