oracle跳跃式索引扫描测试


Oracle 中我们知道能够使用跳跃式索引扫描(Index Skip Scan).然而,能利用跳跃式索引扫描的情况其实是有些限制的CREATE TABLE test AS SELECT ROWNUM a,ROWNUM-1 b,ROWNUM-2 c,ROWNUM-3 d,ROWNUM-4 e FROM all_objects;sql> CREATE TABLE test AS SELECT ROWNUM a,ROWNUM-4 e FROM all_objects;Table created.Elapsed: 00:00:02.78sql> desc test;Name Null? Type----------------------------------------------------- -------- ------------------------------------A NUMBERB NUMBERC NUMBERD NUMBERE NUMBERSELECT DISTINCT COUNT (a) FROM test;sql> SELECT DISTINCT COUNT (a) FROM test; COUNT(A)---------- 84394CREATE INDEX test_idx ON test(a,b,c);sql> create index test_idx on test(a,c);Index created.ANALYZE TABLE test COMPUTE STATISTICS;SET autotrace traceonly explain;SELECT * FROM test WHERE b = 99;sql> analyze table test compute statistics;Table analyzed.Elapsed: 00:00:02.46sql> set autotrace traceonly explain;sql> select * from test where b=99;Elapsed: 00:00:00.00Execution Plan----------------------------------------------------------Plan hash value: 1357081020--------------------------------------------------------------------------| Id | Operation | Name | Rows | Bytes | Cost (%cpu)| Time |--------------------------------------------------------------------------| 0 | SELECT STATEMENT | | 1 | 20 | 96 (2)| 00:00:02 ||* 1 | TABLE ACCESS FULL| TEST | 1 | 20 | 96 (2)| 00:00:02 |--------------------------------------------------------------------------Predicate Information (identified by operation id):--------------------------------------------------- 1 - filter("B"=99) -可见这里CBO选择了全表扫描我们接着做另一个测试drop table test;CREATE TABLE test AS SELECT DECODE(MOD(ROWNUM,2),'1','2' ) a,ROWNUM-4 e FROM all_objects set autotrace offselect distinct a from test;sql> select distinct a from test;A-12Elapsed: 00:00:00.08CREATE INDEX test_idx ON test(a,c)sql> SELECT * FROM test WHERE b = 99;Elapsed: 00:00:00.01Execution Plan----------------------------------------------------------Plan hash value: 2705879578----------------------------------------------------------------------------------------| Id | Operation | Name | Rows | Bytes | Cost (%cpu)| Time |----------------------------------------------------------------------------------------| 0 | SELECT STATEMENT | | 1 | 17 | 4 (0)| 00:00:01 || 1 | TABLE ACCESS BY INDEX ROWID| TEST | 1 | 17 | 4 (0)| 00:00:01 ||* 2 | INDEX SKIP SCAN | TEST_IDX | 1 | | 3 (0)| 00:00:01 |----------------------------------------------------------------------------------------Predicate Information (identified by operation id):--------------------------------------------------- 2 - access("B"=99) filter("B"=99)结论:Oracle的优化器(这里指的是CBO)能对查询应用Index Skip Scans至少要有几个条件:1 优化器认为是合适的.2 索引中的前导列的唯一值的数量能满足一定的条件.3 优化器要知道前导列的值分布(通过分析/统计表得到)4 合适的sql语句

相关文章

数据库版本:11.2.0.4 RAC(1)问题现象从EM里面可以看到,在23号早上8:45~8:55时,数据库等待会话暴增...
(一)问题背景最近在对一个大约200万行数据的表查看执行计划时,发现存在异常,理论上应该返回100多万...
(一)删除备份--DELETE命令用于删除RMAN备份记录及相应的物理文件。当使用RMAN执行备份操作时,会在RM...
(1)DRA介绍 数据恢复顾问(Data Recovery Advise)是一个诊断和修复数据库的工具,DRA能够修复数据文...
RMAN(Recovery Manager)是Oracle恢复管理器的简称,是集数据库备份(backup)、修复(restore)和恢复...
(1)备份对象 可以使用RMAN进行的备份对象如下: --整个数据库:备份所有的数据文件和控制文件; --数...