博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Index Skip Scan in Oracle in 11g
阅读量:5895 次
发布时间:2019-06-19

本文共 3968 字,大约阅读时间需要 13 分钟。

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

0SELECT 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

 
 
 Get our Articles via Email. Enter your email address.
 
Send Me Tutorials

YOU MAY ALSO LIKE...

2 COMMENTS

  1. Keshaba

    Good 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.

  2. anonymous

    good article

LEAVE A REPLY

转载于:https://www.cnblogs.com/feiyun8616/p/9642631.html

你可能感兴趣的文章
我的友情链接
查看>>
16、MariaDB工作中遇到的一部分报错的解决方法
查看>>
jdk的fastdebug版本是什么
查看>>
ConcurrentLinkedQueue cas实现分析
查看>>
在论坛中出现的比较难的sql问题:13(循环替换问题)
查看>>
简单的Samba服务器安装
查看>>
blog addr
查看>>
如何选择 Web 前端模板引擎?
查看>>
VMware 上Clone Ubuntu虚拟机后找不到eth0
查看>>
由毫秒(ms)转换为日期和时间的格式(简单易用)
查看>>
一个女生对BootStrap的感情
查看>>
VMware VIX API使用教程
查看>>
The Shared folder with you
查看>>
Servlet+JSP+MySQL实现用户管理模块之七、实现用户信息更新和重置密码
查看>>
动态规划本质理解:01背包问题
查看>>
微软官方32位版Windows Server 2008下载
查看>>
简单纪要:java 从txt文本中 读取数据
查看>>
Nginx+FastCGI运行原理
查看>>
笔记——搭建简易NFS服务
查看>>
虚拟磁盘恢复虚拟机
查看>>