官网对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. vs调试 本地IIS

    http://www.cnblogs.com/minesky/p/3389955.html 准备篇-配置IIS环境 网站发布到测试环境或者生产后,经常会出现各种让人解不开的疑问,想调试也调试不了.可以 ...

  2. MySQL对于datetime 源码分析

    http://tsecer.blog.163.com/blog/static/150181720160117355684/   一.时间比较的语法分析 在mysql中,通常时间是一个必不可少的类型,而 ...

  3. Io_Language

    Object ancestor := method ( prototype := self proto if (prototype != Obejct, writeln ("Slots of ...

  4. 编译LFS

    成功编译并运行linux from scratch 7.7 system,有必要作下总结.本次用的编译LFS的环境是: 虚拟机是virtalbox宿主系统为CentOS 7.0 x86_64 (cor ...

  5. Java并发——显示锁

    Java提供一系列的显示锁类,均位于java.util.concurrent.locks包中. 锁的分类: 排他锁,共享锁 排他锁又被称为独占锁,即读写互斥.写写互斥.读读互斥. Java的ReadW ...

  6. print之模块化

    这里参考特权同学的模块化思想,将常用的print等任务模块化,便于直接调用,提高代码的效率和易读性.现转载之,以供日后的学习和工作参考. print模块参考代码如下: //============== ...

  7. Java read()和readLine()的区别

    1.read() 功能:读取单个字符的个数,如果已经读完的话会返回-1 (其范围从 0 到 65535 ) 例子如下: byte[] buf = new byte[1024]; int len; wh ...

  8. elasticsearch学习一、安装和配置

    原文链接:http://jingyan.baidu.com/article/48206aead42b53216bd6b372.html ElasticSearch是一个基于Lucene的搜索服务器.它 ...

  9. Java对象与Json之间的转换

    使用Jackson的ObjectMapper对象的readValue和writeValueAsString方法可以进行转换. 对于简单基本类型或String类型的对象,使用上述方法可以满足. 但是如果 ...

  10. 一个react的完整项目展示

    和一些人的关系像平行线,一辈子相守相望,见于眼底藏于心间.就怕耐不住寂寞,冲动而成了相交线,在一个点尽情拥抱,从此便离得越来越远,再也不见.遇到这样的人,因为不想做恋人只能一时,所以才选择做朋友能一世 ...