官网对skip index scan的解释:
Index skip scans improve index scans by nonprefix columns since it is often faster to scan index blocks than scanning table data blocks.
In this case a composite index is split logically into smaller subindexes. The number of logical subindexes depends on the cardinality of the initial column. Hence it is now possible to use the index even if the leading column is not used in a where clause.
从上面描述看,Oracle会对复合索引进行逻辑划分,分成多个子索引。逻辑子索引的个数依赖于前导列不同值个数,即使where子句中不使用前导列索引,仍有可能会使用到索引。
 
必须满足条件:
1、OPTIMIZER为CBO
2、Oracle 版本在9i以上
3、相关表和索引要进行过分析
 
skip scan会探测出索引前导列的唯一值个数,每个唯一值都会作为常规扫描的入口,在此基础上做一次查找,最后合并这些查询。例如:
表t1中有一个组合索引(owner,object_id),其中owner只有test和sys两个值。在索引跳跃的情况下,我们可以逻辑上把他们看成两个索引,一个是('TEST',object_id),一个是('SYS',object_id).
select * from t1 where object_id=1;
发出这个查询后,oracle先进入owner为test的入口,查找object_id=1的条目。再进入owner为sys的入口,查找object_id=1的条目。最后合并两个结果集。
另外可以使用index_ss来强制选择skip index scan索引。
 
一个疑惑:
SQL> create table t1 as select * from dba_objects;
SQL> create index i_t1_owner on t1(owner,object_id);
SQL> exec dbms_stats.gather_table_stats(user,'t1');
 
SQL> select owner,count(*) from t1 group by owner;

OWNER                            COUNT(*)
------------------------------ ----------
PUBLIC                               3360
OUTLN                                   9
TEST                                    4
SYSTEM                                527
ORACLE_OCM                              8
SCOTT                                   6
DBSNMP                                 55
APPQOSSYS                               5
SYS                                  9094
WMSYS                                 318

已选择10行。

 
SQL> set autot trace
SQL> select count(*) from t1 where object_id=2 and owner>'TEST';

已用时间:  00: 00: 00.01

执行计划
----------------------------------------------------------
Plan hash value: 2159330979

-------------------------------------------------------------------------------
| Id  | Operation        | Name       | Rows  | Bytes | Cost (%CPU)| Time     |
-------------------------------------------------------------------------------
|   0 | SELECT STATEMENT |            |     1 |    10 |     3   (0)| 00:00:01 |
|   1 |  SORT AGGREGATE  |            |     1 |    10 |            |          |
|*  2 |   INDEX SKIP SCAN| I_T1_OWNER |     1 |    10 |     3   (0)| 00:00:01 |
-------------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

2 - access("OWNER">'TEST' AND "OBJECT_ID"=2 AND "OWNER" IS NOT NULL)
       filter("OBJECT_ID"=2)

统计信息
----------------------------------------------------------
          5  recursive calls
          0  db block gets
         27  consistent gets
          0  physical reads
          0  redo size
        422  bytes sent via SQL*Net to client
        415  bytes received via SQL*Net from client
          2  SQL*Net roundtrips to/from client
          0  sorts (memory)
          0  sorts (disk)
          1  rows processed

 
为什么这里明明使用了整个索引,为什么还是走了index skip scan呢?不是应该index range scan吗?
从谓词信息里看:
   2 - access("OWNER">'TEST' AND "OBJECT_ID"=2 AND "OWNER" IS NOT NULL)
       filter("OBJECT_ID"=2)
虽然扫描了整个索引块,但是却对索引块进行了 filter("OBJECT_ID"=2)过滤。
 

skip index scan的更多相关文章

  1. MySQL的loose index scan

    众所周知,InnoDB采用IOT(index organization table)即所谓的索引组织表,而叶子节点也就存放了所有的数据,这就意味着,数据总是按照某种顺序存储的.所以问题来了,如果是这样 ...

  2. Index Seek和Index Scan的区别

    Index Seek是Sql Server执行查询语句时利用建立的索引进行查找,索引是B树结构,Sql Server先查找索引树的根节点,一级一级向下查找,在查找到相应叶子节点后,取出叶子节点的数据. ...

  3. 数据库的Index Scan V.S. Rscan

    一直在做performance,但直到今天才完成了这个第一天应该完成的图,到底Index scan和Rscan的分界点在哪里?   如下图所示,很简单的一个查询,只是查询int,分别强制走索引和表扫描 ...

  4. index seek与index scan

    原文地址:http://blog.csdn.net/pumaadamsjack/article/details/6597357 低效Index Scan(索引扫描):就全扫描索引(包括根页,中间页和叶 ...

  5. 关于mysql的loose index scan的几点疑问

    本文同时发表在https://github.com/zhangyachen/zhangyachen.github.io/issues/102 关于MySQL的loose index scan有几点疑问 ...

  6. Sql Server中的表访问方式Table Scan, Index Scan, Index Seek

    1.oracle中的表访问方式 在oracle中有表访问方式的说法,访问表中的数据主要通过三种方式进行访问: 全表扫描(full table scan),直接访问数据页,查找满足条件的数据 通过row ...

  7. 转:Sql Server中的表访问方式Table Scan, Index Scan, Index Seek

    0.参考文献 Table Scan, Index Scan, Index Seek SQL SERVER – Index Seek vs. Index Scan – Diffefence and Us ...

  8. index seek和index scan 提高sql 效率

    index seek和index scan 提高sql 效率解释解释index seek和index scan:索引是一颗B树,index seek是查找从B树的根节点开始,一级一级找到目标行.ind ...

  9. Clustered Index Scan 与 Clustered Index Seek

    Clustered Index Scan 与 Clustered Index Seek 在利用 SQL Server 查询分析器的执行计划中,会有许多扫描方式,其中就有 Clustered Index ...

随机推荐

  1. Dragons

    http://codeforces.com/problemset/problem/230/A Dragons time limit per test 2 seconds memory limit pe ...

  2. ubuntu14.04源代码安装postgresql 9.1

    项目须要使用gisgraphy,怎奈gisgraphy3.0仅仅支持postgis1.5.因此仅仅能安装老版本号的posgresql和postgis了.从postgis的support matrix图 ...

  3. Lua开发环境搭建(Mac)

    1.下载最新版的Lua,点击下载 2.下载完成后,解压压缩包,打开终端,cd进入Lua解压目录下 3. 在终端输入“make macosx”,编译lua 4.编译完成后,在终端输入”make test ...

  4. Java基础知识强化之集合框架笔记71:模拟斗地主洗牌和发牌并对牌进行排序的案例

    1. 模拟斗地主洗牌和发牌并对牌进行排序的原理图解: 2. 代码实现: 思路: • 创建一个HashMap集合 • 创建一个ArrayList集合 • 创建花色数组和点数数组 • 从0开始往HashM ...

  5. Swift之语法1(精简版)

    1. Swift简介 2010年的夏天,苹果公司的开发人员Chris Lattne接到了一个特别的任务,为OS X 和iOS平台开发下一代的编程语言,也就是Swift. 苹果公司于2014年WWDC( ...

  6. iOS 跳转至 指定 StoryBoard 中 指定的 Scene

    UIStoryboard *stryBoard=[UIStoryboard storyboardWithName:@"second" bundle:nil]; UIViewCont ...

  7. 实现一个脚本语言Raven(一)

    之前实现了Raven语言的0.1版,仅仅支持表达式处理与控制语句,由于不支持数组.函数.类,甚至都不是图灵完全的语言. 现在参考vczh的博客打算重新写一遍Raven语言.陈祖不愧是神啊,高中就写出支 ...

  8. 我给自己的Sass+Compass,在Windows下写个bat,快速cd到我的sass目录

    在Windows下,我总是要打开Ruby的cmd来进行Sass,其中要写好多cd,次数多了,自己的多敲,的确能记得更牢靠,但是无形中会浪费自己的一点点敲cd命令的时间,所以我想到自己在windows下 ...

  9. 利用javascript实现文本的自动输出

    主要利用了setTimeout(),递归和String.substring(); 做出的效果就像是有一个打字员在打字. <!doctype html> <html lang=&quo ...

  10. Git之路--1

    昨天下午到今天早上,终于搞定了github.过程很难过,不过看到自己的github上有代码了.还是小小的开心了一下.暂时没时间分享相关技术,附带微博链接,有想试试上传上Github的小伙伴可以查看我的 ...