官网对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. Eclipse错误

    1.java compiler level does not match the version of the installed java project facet 解决:http://blog. ...

  2. Java并发——同步工具类

    CountDownLatch  同步倒数计数器 CountDownLatch是一个同步倒数计数器.CountDownLatch允许一个或多个线程等待其他线程完成操作. CountDownLatch对象 ...

  3. Spring MVC中如何传递对象参数

    springController: @Controller @RequestMapping("/user") public UserController extends BaseC ...

  4. Eclipse部署多个Web项目内存溢出,java.lang.OutOfMemoryError: PermGen space

    Eclipse部署多个Web项目内存溢出,java.lang.OutOfMemoryError: PermGen space >>>>>>>>>& ...

  5. ThinkPHP函数详解:cache方法

    cache方法是3.0版本开始新增的缓存管理方法.注意:3.1.2版本后因cache方法并入原S方法,所以cache方法不再建议使用,用S方法即可. cache 用于缓存设置.获取.删除操作 用法ca ...

  6. MySQL中的datetime与timestamp比较

    引用:http://database.51cto.com/art/200905/124240.htm TIMESTAMP列的显示格式与DATETIME列相同.换句话说,显示宽度固定在19字符,并且格式 ...

  7. iOS 指纹解锁

    目前常用的App支持指纹解锁的还不是很多,如果在你的项目中用一下是不是显得高大上呢? 废话不说多,干货- 1.在工程中添加LocalAuthentication.framework 2.在需要验证的c ...

  8. 小改动,大作为——C# 4.0中的微小改动

    1.可选参数和命名实参 可选参数和命名实参就如同一对好基友,因为它们经常一起使用. 1.1 可选参数 可选参数重在“可选”,即在调用方法时,该参数可以明确指定实参,也可以不指定.如下代码所示,下面代码 ...

  9. Http上传文件

    public class UpLoadFile { public static void UpLoadFiles(string fileName) { string fileType = Path.G ...

  10. javascript 基础3第13节

    <html> <head> <title>javascript基础</title> </head> <body> 1.流程控制 ...