oracle skipscan,关于Oracle 9i 跳跃式索引扫描(Index Skip Scan)的小测试-数据库专栏,ORACLE...

在oracle9i中我们知道能够使用跳跃式索引扫描(index skip scan).然而,能利用跳跃式索引扫描的情况其实是有些限制的.

从oracle的文档中我们可以找到这样的话:

index skip scans

index skip scans improve index scans by nonprefix columns.

often, scanning index blocks is faster than scanning table data blocks.

skip scanning lets a composite index be split logically into smaller subindexes.

in skip scanning, the initial column of the composite index is not specified in the query.

in other words, it is skipped.

the number of logical subindexes is determined by the number of distinct values in the initial column.

skip scanning is advantageous if there are few distinct values in the leading column of the composite

index and many distinct values in the nonleading key of the index.

也可以这样说,优化器根据索引中的前导列(索引到的第一列)的唯一值的数量决定是否使用skip scan.

我们首先做个测试:

sql> create table test as

2  select rownum a,rownum-1 b ,rownum-2 c,rownum-3 d,rownum-4 e

3  from all_objects

4  /

sql> select distinct count (a) from test;

count(a)

———-

28251

表已创建。

sql>

sql> create index test_idx on test(a,b,c)

2  /

索引已创建。

sql> analyze table test compute statistics

2  for table

3  for all indexes

4  for all indexed columns

5  /

表已分析。

sql> set autotrace traceonly explain

sql> select *  from test where b = 99

2  /

execution plan

———————————————————-

0      select statement optimizer=choose (cost=36 card=1 bytes=26)

1    0 table access (full) of test (cost=36 card=1 bytes=26)

–可见这里cbo选择了全表扫描.

–我们接着做另一个测试:

sql> drop table test;

表已丢弃。

sql> create table test

2  as

3  select decode(mod(rownum,2), 0, 1, 2 ) a,

4                    rownum-1 b,

5                    rownum-2 c,

6                    rownum-3 d,

7                    rownum-4 e

8    from all_objects

9  /

表已创建。

sql> set autotrace off

sql> select distinct a from test;

a

1

2

–a列只有两个唯一值

sql> create index test_idx on test(a,b,c)

2  /

索引已创建。

sql> analyze table test compute statistics

2  for table

3  for all indexes

4  for all indexed columns

5  /

表已分析。

sql> set autotrace traceonly explain

sql> select *  from test where b = 99

2  /

execution plan

———————————————————-

0      select statement optimizer=choose (cost=4 card=1 bytes=24)

1    0   table access (by index rowid) of test (cost=4 card=1 bytes=24)

2    1     index (skip scan) of test_idx (non-unique) (cost=3 card=1)

oracle的优化器(这里指的是cbo)能对查询应用index skip scans至少要有几个条件:

1 优化器认为是合适的.

2 索引中的前导列的唯一值的数量能满足一定的条件.

3 优化器要知道前导列的值分布(通过分析/统计表得到)

4 合适的sql语句

……

更多信息请参考:

http://www.itpub.net/showthread.php?threadid=85948

http://www.cnoug.org/bin/ut/topic_show.cgi?id=608&h=1&bpg=1&age=100

http://www.itpub.net/showthread.php?s=&postid=985602#post985602

oracle9i database performance tuning guide and reference release 2 (9.2)

part number a96533-02

感谢参加讨论的各位高手.

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值