Index Skip Scan in Oracle in 11g
http://viralpatel.net/blogs/oracle-index-skip-scan/
in 11g the same sql use index skip scan but in 10g it use index rang scan ,it seem the same sql ,10g is better
With Oracle 9i, the Cost-Based Optimizer (CBO) is equipped with many useful features, one of them is “Index skip scan“. In previous releases a composite index could only be used if the first column, the leading edge, of the index was referenced in the WHERE clause of a statement. In Oracle 9i this restriction is removed because the optimizer can perform skip scans to retrieve rowids for values that do not use the prefix. This means even if you have a composite index on more than one column and you use the non-prefix column alone in your SQL, it may still use index. (Earlier I use to think that it will not use index :))
Its not always guaranteed that the Index Skip Scan will be used, this is because Cost-Based Optimizer (CBO) will calculate the cost of using the index and if it is more than that of full table scan, then it may not use index.
This approach is advantageous because:
- It reduces the number of indexes needed to support a range of queries. This increases performance by reducing index maintenance and decreases wasted space associated with multiple indexes.
- The prefix column should be the most discriminating and the most widely used in queries. These two conditions do not always go hand in hand which makes the decision difficult. In these situations skip scanning reduces the impact of making the “wrong” decision.
Index skip scan works differently from a normal index (range) scan. A normal range scan works from top to bottom first and then move horizontal. But a Skip scan includes several range scans in it. Since the query lacks the leading column it will rewrite the query into smaller queries and each doing a range scan.
Consider following example where we create a test
table and create index on first two columns a
and b
. Also we put some dummy data inside test
table. See how Index is getting selected when we execute select
statement with column b
in where
clause.
Step 1:
CREATE TABLE test (a NUMBER, b NUMBER, c NUMBER);
Table created.
Step 2:
CREATE INDEX test_i
ON test (a, b);
Index created.
Step 3:
BEGIN
FOR i IN 1 .. 100000
LOOP
INSERT INTO test
VALUES (MOD (i, 5), i, 100);
END LOOP;
COMMIT;
END;
/
PL/SQL procedure successfully completed.
Step 4:
exec dbms_stats.gather_table_stats (
ownname => 'gauravsoni',
tabname => 'test',
cascade => true
);
PL/SQL procedure successfully completed.
Step 5:
set autotrace trace exp
Step 6:
SELECT *
FROM test
WHERE b = 95267;
Execution Plan
0
SELECT STATEMENT Optimizer=ALL_ROWS (Cost=22 Card=1 Bytes=10)
1 0
TABLE ACCESS (BY INDEX ROWID) OF 'TEST' (TABLE) (Cost=22 Card=1 Bytes=10)
2 1
INDEX (SKIP SCAN) OF 'TEST_I' (INDEX) (Cost=21 Card=1)
I above example, "select * from test where b=95267"
was broken down to several small range scan queries. It was effectively equivalent to following:
SELECT *
FROM test
WHERE a = 0 AND b = 95267
UNION
SELECT *
FROM test
WHERE a = 1 AND b = 95267
UNION
SELECT *
FROM test
WHERE a = 2 AND b = 95267
UNION
SELECT *
FROM test
WHERE a = 3 AND b = 95267
UNION
SELECT *
FROM test
WHERE a = 4 AND b = 95267;
In concrete, saying that skip scan is not as efficient as normal “single range scan” is correct. But yet saves some disk space and overhead of maintaining another index.
Reference
Oracle Documentation on Index Skip Scan
Related Articles
- Index usage with LIKE operator in Oracle & Domain Indexes
- Invisible Indexes in Oracle 11g
- Oracle Skip Locked
- Row Data Multiplication in Oracle
- Oracle 11G new feature: Virtual Column
- Fetch Random rows from Database (MySQL, Oracle, MS SQL, PostgreSQL)
- Understanding Primary Key(PK) Constraint in Oracle
Send Me Tutorials
Tags: database indexesOracleoracle-11g
- NEXT STORYJava MD5 Hashing & Salting: Secure Your Passwords
- PREVIOUS STORYPagination in Oracle using ROWNUM and Limiting Result Set
YOU MAY ALSO LIKE...
2 COMMENTS
Keshaba
7 June, 2012, 0:11Good Article. The usage of index skip scan depends on the cardinality of the leading column. When the cardinality is low, means there are few distinct values in the leading column, index skip scan comes into effect. However as you have described it is not much efficient compared to other index scans like range scan.
LEAVE A REPLY
Index Skip Scan in Oracle in 11g的更多相关文章
- 深入理解Oracle索引(1):INDEX SKIP SCAN 和 INDEX RANGE SCAN
㈠ Index SKIP SCAN 当表有一个复合索引,而在查询中有除了索引中第一列的其他列作为条件,并且优化器模式为CBO,这时候查询计划就有可能使用到SS ...
- 索引跳跃式扫描(INDEX SKIP SCAN)
索引跳跃式扫描(INDEX SKIP SCAN) 索引跳跃式扫描(INDEX SKIP SCAN)适用于所有类型的复合B树索引(包括唯一性索引和非唯一性索引),它使那些在where条件中没有对目标索引 ...
- INDEX SKIP SCAN适用场景
--请记住这个INDEX SKIP SCAN扫描方式 drop table t purge;create table t as select * from dba_objects;update t s ...
- oralce索引中INDEX SKIP SCAN 和 INDEX RANGE SCAN区别
INDEX SKIP SCAN 当表中建立有复合索引的时候,查询时,除复合索引第一列外,别的列作为条件时,且优化器模式为CBO,这个时候查询可能会用到INDEX SKIP SCAN skip scan ...
- 【每日一摩斯】-Index Skip Scan Feature (212391.1)
INDEX Skip Scan,也就是索引快速扫描,一般是指谓词中不带复合索引第一列,但扫描索引块要快于扫描表的数据块,此时CBO会选择INDEX SS的方式. 官方讲的,这个概念也好理解,如果将复合 ...
- index range scan,index fast full scan,index skip scan发生的条件
源链接:https://blog.csdn.net/robinson1988/article/details/4980611 index range scan(索引范围扫描): 1.对于unique ...
- Oracle 11G INDEX FULL SCAN 和 INDEX FAST FULL SCAN 对比分析
SQL> drop table test; 表已删除. SQL> create table test as select * from dba_objects where 1!=1; 表已 ...
- Oracle分区表之分区范围扫描(PARTITION RANGE ITERATOR)与位图范围扫描(BITMAP INDEX RANGE SCAN)
一.前言: 一开始分区表和位图索引怎么会挂钩呢?可能现实就是这么的不期而遇:比如说一张表的字段是年月日—‘yyyy-mm-dd’,重复率高吧,适合建位图索引吧,而且这张表数据量也不小,也适合转换成分区 ...
- [20180316]为什么不使用INDEX FULL SCAN (MIN/MAX).txt
[20180316]为什么不使用INDEX FULL SCAN (MIN/MAX).txt --//链接:http://www.itpub.net/thread-2100456-1-1.html.自己 ...
随机推荐
- Qemu虚拟机 玩树莓派最新版系统 (截止2017-04-10)
Qemu虚拟机可以玩 树莓派,大家都知道了吧.可是网上的教程好老,都是2012年的.我按照教程下载了最新版版本的树莓派系统怎么也跑不起来. 研究了好久,终于找到一个简单的方法,特意分享出来.转载请注意 ...
- Bootstrap 组件之 List group
简介 List group 指列表.当然,Bootstrap 列表不局限于由 <ul> 和 <li> 标签构成的. Bootstrap 中一共三种列表的构成方式,这里 有一个例 ...
- [译]Javascript中的循环
本文翻译youtube上的up主kudvenkat的javascript tutorial播放单 源地址在此: https://www.youtube.com/watch?v=PMsVM7rjupU& ...
- [转]Passing Managed Structures With Strings To Unmanaged Code Part 1
1. Introduction. 1.1 Managed structures that contain strings are a common sight. The trouble is that ...
- TensorFlow实现卷积神经网络
1 卷积神经网络简介 在介绍卷积神经网络(CNN)之前,我们需要了解全连接神经网络与卷积神经网络的区别,下面先看一下两者的结构,如下所示: 图1 全连接神经网络与卷积神经网络结构 虽然上图中显示的全连 ...
- rabbitmq常用命令行汇总
最近处理openstack问题时,碰到了rabbitmq相关的问题,使用相关命令行时,经常去现找相关的帖子,感觉很麻烦,记录下自己定位问题时,用到的一些常用命令行,方便以后问题的查找 1)常用的一些查 ...
- Binder学习笔记(五)—— Parcel是怎么打包数据的?
前文中曾经遇到过Parcel,从命名上知道他负责数据打包.在checkService的请求/响应体系中,Parcel只打包了基本数据类型,如Int32.String16……后面还要用于打包抽象数据类型 ...
- 等和的分隔子集(DP)
晓萌希望将1到N的连续整数组成的集合划分成两个子集合,且保证每个集合的数字和是相等.例如,对于N=3,对应的集合{1,2,3}能被划分成{3} 和 {1,2}两个子集合. 这两个子集合中元素分别的和是 ...
- Tomcat—Bad Request
前段时间,由于搭建环境的问题,项目暂停了一个多月,终于再次拿起来了,可是历史问题还是没有解决,再次让问题重现了一把. 上面的图片的大概意思就是:错误请求(无效主机名称) 看到这个,我一开始是兴 ...
- BZOJ1096 [ZJOI2007]仓库建设(斜率优化)
题目背景 小B的班级数学学到多项式乘法了,于是小B给大家出了个问题:用编程序来解决多项式乘法的问题. 题目描述 L公司有N个工厂,由高到底分布在一座山上. 工厂1在山顶,工厂N在山脚. 由于这座山处于 ...