oracle 反向索引

反向索引就是将正常的键值头尾调换后再进行存储,比如原值是“1234”,将会以“4321”形式进行存储,这样做可以高效地打散正常的索引键值在索引叶块中的分布位置。

1. 反向索引应用场合
1)发现索引叶块成为热点块时使用
通常,使用数据时(常见于批量插入操作)都比较集中在一个连续的数据范围内,那么在使用正常的索引时就很容易发生索引叶子块过热的现象,严重时将会导致系统性能下降。
2)在RAC环境中使用
当RAC环境中几个节点访问数据的特点是集中和密集,索引热点块发生的几率就会很高。如果系统对范围检索要求不是很高的情况下可以考虑使用反向索引技术来提高系统的性能。因此该技术多见于RAC环境,它可以显著的降低索引块的争用。

2.使用反向索引的优点
最大的优点莫过于降低索引叶子块的争用,减少热点块,提高系统性能。

3.使用反向索引的缺点
由于反向索引结构自身的特点,如果系统中经常使用范围扫描进行读取数据的话(例如在where子句中使用“between and”语句或比较运算符“>”“<”等),那么反向索引将不适用,因为此时会出现大量的全表扫描的现象,反而会降低系统的性能。

4.通过一个小实验简单演示一下反向索引的创建及修改
1)创建一个实验表T
sec@ora10g> create table t (x int);

Table created.

2)创建反向索引,在正常创建索引的语句后面简单的加上“reverse”关键字即可。
sec@ora10g> create index idx_t on t(x) reverse;

Index created.

3)使用user_indexes视图查看一下索引的类型,“NORMAL/REV”表示该索引类型为反向索引。
sec@ora10g> col TABLE_NAME for a10
sec@ora10g> col INDEX_NAME for a10
sec@ora10g> select table_name, index_name, index_type from user_indexes where table_name = 'T';

TABLE_NAME INDEX_NAME INDEX_TYPE
---------- ---------- ---------------
T          IDX_T      NORMAL/REV

4)修改反向索引为正常索引
当反向索引无法满足我们的需求的时候,我们可能会考虑修改反向索引为正常的索引结构。
除了删除索引重新创建这种方法外,可以直接使用noreverse选项重新rebuild索引。
sec@ora10g> alter index idx_t rebuild noreverse;

Index altered.

5)最后确认一下,该索引已经修改为正常的索引。
sec@ora10g> select table_name, index_name, index_type from user_indexes where table_name = 'T';

TABLE_NAME INDEX_NAME INDEX_TYPE
---------- ---------- ---------------
T          IDX_T      NORMAL

5.Oracle 10gR2官方文档有关反向索引的描述。可谓“清澈见底”。
http://download.oracle.com/docs/cd/B19306_01/server.102/b14220/schema.htm#sthref998

Reverse Key Indexes

Creating a reverse key index, compared to a standard index, reverses the bytes of each column indexed (except the rowid) while keeping the column order. Such an arrangement can help avoid performance degradation with Real Application Clusters where modifications to the index are concentrated on a small set of leaf blocks. By reversing the keys of the index, the insertions become distributed across all leaf keys in the index.

Using the reverse key arrangement eliminates the ability to run an index range scanning query on the index. Because lexically adjacent keys are not stored next to each other in a reverse-key index, only fetch-by-key or full-index (table) scans can be performed.

Sometimes, using a reverse-key index can make an OLTP Real Application Clusters application faster. For example, keeping the index of mail messages in an e-mail application: some users keep old messages, and the index must maintain pointers to these as well as to the most recent.

The REVERSE keyword provides a simple mechanism for creating a reverse key index. You can specify the keyword REVERSE along with the optional index specifications in a CREATE INDEX statement:

CREATE INDEX i ON t (a,b,c) REVERSE;

You can specify the keyword NOREVERSE to REBUILD a reverse-key index into one that is not reverse keyed:

ALTER INDEX i REBUILD NOREVERSE;


Rebuilding a reverse-key index without the NOREVERSE keyword produces a rebuilt, reverse-key index.

6.小结
可以充分发挥反向索引减少索引热点块的优势对系统进行调优,不过反向索引本身的结构特点也限定了它的应用范围。因此需要具体问题具体分析,实施前做好充分的测试。

本篇文章来源于:开发学院 http://edu.codepub.com   原文链接:http://edu.codepub.com/2010/0429/22435.php

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值