10g新增初始化参数SKIP_UNUSABLE_INDEXES

这个10.1就增加的新特性,是最近才发现的。

 

SQL> create table t_index (id number, name varchar2(30));

Table created.

SQL> create index ind_t_id on t_index(id);

Index created.

SQL> create index ind_t_name on t_index(name);

Index created.

SQL> insert into t_index values (1, 'a');

1 row created.

SQL> commit;

Commit complete.

SQL> alter table t_index move;

Table altered.

SQL> select index_name, status from user_indexes where table_name = 'T_INDEX';

INDEX_NAMESTATUS
------------------------------ --------
IND_T_ID UNUSABLE
IND_T_NAME UNUSABLE

SQL> insert into t_index values (2, 'b');

1 row created.

当这个插入语句成功后,我发现自己做的例子居然和预期产生了差异,在我的印象中,这个插入语句是应该报错的。

随后马上做了三件事情:

SQL> select * from v$version;

BANNER
----------------------------------------------------------------
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi
PL/SQL Release 10.2.0.4.0 - Production
CORE 10.2.0.4.0 Production
TNS for Linux: Version 10.2.0.4.0 - Production
NLSRTL Version 10.2.0.4.0 - Production

SQL> select index_name, status from user_indexes where table_name = 'T_INDEX';

INDEX_NAMESTATUS
------------------------------ --------
IND_T_ID UNUSABLE
IND_T_NAME UNUSABLE

SQL> show parameter index

NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
optimizer_index_caching integer 0
optimizer_index_cost_adj integer 100
skip_unusable_indexes boolean TRUE

首先第一件事情就是坚持当前数据库的版本,我可以确定在9i,最后一个INSERT会由于索引的状态不可用而导致错误,而当前可以执行成功,因此首先确定版本问题。

在确认是10.2版本后,随后又坚持了一下索引的状态,看看是否插入导致Oracle重建了索引。而当前索引的状态并未发生变化,说明Oracle在执行插入时,跳过了这些不可用的索引。

于是顺理成章的就是第三个动作,坚持包含index关键字的初始化参数,看看是否是10g中存在了一个类似的初始化参数,使得索引在不可用状态下,基表同样可以进行DML操作。

查询果然发现了这个参数,而且从名称以及设置的值来看,确认就是要找的初始化参数:

SQL> alter session set skip_unusable_indexes = false;

Session altered.

SQL> insert into t_index values (3, 'c');
insert into t_index values (3, 'c')
*
ERROR at line 1:
ORA-01502: index 'TEST.IND_T_ID' or partition of such index is in unusable state


SQL> alter index ind_t_id rebuild;

Index altered.

SQL> alter index ind_t_name rebuild;

Index altered.

SQL> insert into t_index values (3, 'c');

1 row created.

SQL> commit;

Commit complete.

将初始化参数设置为FALSE后,数据库的行为果然表现的和9i中一致。

查询了一下Oracle的文档,发现在10.1Oracle已经引入了这个初始化参数。这个参数的引入可以避免由于表MOVE或其他DDL导致的索引失效,从而影响到整个表的可用性,同时这个参数的引入也会存在问题,它使得本来可以很快发现的问题埋藏的很深,甚至可能造成严重的性能隐患。

当然Oracle也意识到这一点,在告警日志中可以看到这些的提示信息:

Sat Dec 31 10:53:33 2011
Some indexes or index [sub]partitions of table TEST.T_INDEX have been marked unusable

这同样也说明,任何一个参数都有两个方面,如果设置参数后只有优点而没有缺点,Oracle也就没有必要让用户去选择了。

Note:

If an index is used to enforce a UNIQUE constraint on a table, then allowing insert and update operations on the table might violate the constraint. Therefore, this setting does not disable error reporting for unusable indexes that are unique.

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值