ITPub博客

首页 > Linux操作系统 > Linux操作系统 > 10g新增初始化参数SKIP_UNUSABLE_INDEXES

10g新增初始化参数SKIP_UNUSABLE_INDEXES

原创 Linux操作系统 作者:yangtingkun 时间:2012-01-02 23:57:50 0 删除 编辑

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

 

 

公司中的新人问起索引失效对表影响,于是随手做了个例子,才发现10g中已经改变了9i中的默认方式:

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_NAME                     STATUS
------------------------------ --------
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_NAME                     STATUS
------------------------------ --------
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.1中Oracle已经引入了这个初始化参数。这个参数的引入可以避免由于表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也就没有必要让用户去选择了。

 

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

下一篇: ORA-600(KGHALO4)错误
请登录后发表评论 登录
全部评论
暂无介绍

注册时间:2007-12-29

  • 博文量
    1964
  • 访问量
    11076238