`

《Pro Oracle SQL》Chapter3--3.2.6 Index Skip Scan

阅读更多

Index Skip Scan    索引跳跃扫描     (page 107)
    An index skip scan is chosen when the predicate contains a condition on a non-leading column in an
index and the leading columns are fairly distinct .
  In earlier releases of Oracle, if a predicate used a
column that wasn’t the leading column in an index, the index couldn’t be chosen.  This behavior
changed in Oracle version 9 with the introduction of the index skip scan .  A skip scan works by logically
splitting a multi-column index into smaller subindexes.  The number of logical subindexes is
determined by the number of distinct values in the leading columns of the index.  Therefore, the more
distinct the leading columns are, the more logical subindexes would need to be created.
  If too many
subindexes would be required, the operation won’t be as efficient as simply doing a full scan.  
However, in the cases where the number of subindexes needed would be smaller, the operation can be
many times more efficient than a full scan as scanning smaller index blocks can be more efficient
than scanning larger table blocks. Listing 3-15 shows an example of an index skip scan plan (Note: For
this example, I used a copy of the hr.employees table which had nearly 28,000 rows).
    当谓词包含的条件(作用)在索引的非前置列上而前置列却十分明显 时,索引跳跃扫描将被选择。 在Oracle的早期版本中,如果谓词使用了索引的非前置列, 索引就不会被选择。该行为随着Oracle 9引入了索引跳跃扫描而改变了。跳跃扫描原理是,把多列索引逻辑划分成小的子索引。逻辑子索引的数量由索引前置列的明显值的个数确定。因此,前置列越 明显,就会创建越多的逻辑子索引。 如果需要创建的逻辑子索引太多,操作的效率可能还比不上直接做全扫描。然而,如果所需的子索引的数量较小,操作的效率将数倍于全扫描,因为扫描较小(范围)的索引块比扫描较大表块更有效率。列表3-15展示了一个索引跳跃扫描的例子(注意:本例中,我使用了 hr.employees表的一备份表有将近28,000行)。
Listing 3-15. Index Skip Scan Examples
SQL> create index emp_jobfname_ix on employees(job_id, first_name, salary);   
 --这里job_id就是前置列
Index created.
 
SQL> set autotrace traceonly 
SQL>
SQL> select * from employees where first_name = 'William';
 
Execution Plan
----------------------------------------------------------
Plan hash value: 3440948136
 
------------------------------------------------------------------------------------
| Id  | Operation                                        | Name                        | Rows  | Bytes | Cost (%CPU)|
------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT                      |                                  |     1 |    82 |    21   (0)|
|   1 |  TABLE ACCESS BY INDEX ROWID| EMPLOYEES             |     1 |    82 |    21   (0)|
|*  2 |   INDEX SKIP SCAN                        | EMP_JOBFNAME_IX |     1 |         |    20   (0)|
------------------------------------------------------------------------------------
 Predicate Information (identified by operation id):
---------------------------------------------------
 
   2 - access("FIRST_NAME"='William')
       filter("FIRST_NAME"='William')
 
Statistics
-------------------------------------------------------
          0  recursive calls
          0  db block gets
         50  consistent gets
          0  physical reads
          0  redo size
       2362  bytes sent via SQL*Net to client
        392  bytes received via SQL*Net from client
          3  SQL*Net roundtrips to/from client
          0  sorts (memory)
          0  sorts (disk)
         23  rows processed
 
SQL> select /*+ full(employees) */ * from employees where first_name = 'William';
 
23 rows selected.
Execution Plan
----------------------------------------------------------
Plan hash value: 1445457117
 
-------------------------------------------------------------------------------
| Id  | Operation                       | Name            | Rows  | Bytes | Cost (%CPU)| Time     |
-------------------------------------------------------------------------------
|   0 | SELECT STATEMENT    |                      |     1 |    82 |    84   (2)| 00:00:02 |
|*  1 |  TABLE ACCESS FULL  | EMPLOYEES     |     1 |    82 |    84   (2)| 00:00:02 |
-------------------------------------------------------------------------------
 
Predicate Information (identified by operation id):
---------------------------------------------------
 
   1 - filter("FIRST_NAME"='William')
Statistics
----------------------------------------------------------
          0  recursive calls
          0  db block gets
        376  consistent gets
          0  physical reads
          0  redo size
       2735  bytes sent via SQL*Net to client
        392  bytes received via SQL*Net from client
          3  SQL*Net roundtrips to/from client
          0  sorts (memory)
          0  sorts (disk)
         23  rows processed
 
SQL> -- How many distinct values of job_id?
SQL> select count(distinct job_id) ct from employees ;
 
             CT
---------------
             19
    In this example, the leading column of the index,  job_id, has 19 distinct values.  Using an index
skip scan to access the 23 rows that match the condition (first_name = ‘William’), there are 50
consistent gets (logical block accesses).  However, if a full table scan is used, 376 blocks are accessed. 
As you can see, the skip scan is much more efficient.  What happened was that the index was logically
divided into 19 subindexes and each subindex was scanned for a match for first_name = ‘William’. 
For this index scan type, just keep in mind that the fewer distinct values the leading column (or
columns) have, the fewer logical subindexes will be needed and therefore the fewer total block
accesses required. 
 
    在例中,索引的前导列,job_id,有19个明显值。使用索引跳跃扫描访问匹配条件(first_name='William')的23行(记录),用了50个一致读 (逻辑块访问)。然而,如果使用全表扫描,就要访问376个块。如你所见,跳跃扫描有效率多了。索引逻辑上划分成19个子索引且扫描每个子索引匹配first_name='William'。对于这种扫描类型,只要记住前置列(或列集)的明显值越少,所需的逻辑子索引越少,则因此所要访问的总块数越少。

0
0
分享到:
评论

相关推荐

    datanucleus-api-jdo-3.2.6-API文档-中文版.zip

    赠送原API文档:datanucleus-api-jdo-3.2.6-javadoc.jar; 赠送源代码:datanucleus-api-jdo-3.2.6-sources.jar; 赠送Maven依赖信息文件:datanucleus-api-jdo-3.2.6.pom; 包含翻译后的API文档:datanucleus-api-...

    spring-cglib-repack-3.2.6.jar和spring-objenesis-repack-2.6.jar

    在提供的文件中,我们看到了两个与Spring相关的库:`spring-cglib-repack-3.2.6.jar` 和 `spring-objenesis-repack-2.6.jar`。这两个库都是Spring框架的重要组成部分,用于解决特定的编程问题。 首先,让我们来了解...

    datanucleus-api-jdo-3.2.6.jar )

    datanucleus-api-jdo-3.2.6.jar )

    rocketmq-console-3.2.6.war

    安装rocketmq的管控台 rocketmq,版本rocketmq-console-3.2.6.war

    spring-cglib-repack-3.2.6.jar,spring-objenesis-repack-2.6.jar

    2018-02-08从git_hub上拉取的Spring源码打成的jar,构建Spring-beans5.0以上源码所缺失的两个jar包spring-cglib-repack-3.2.6.jar,spring-objenesis-repack-2.6.jar

    spring-cglib-repack-3.2.6.jar

    spring-cglib-repack-3.2.6.jar 放在spring-core/build/libs下

    spring-aop-3.2.6.RELEASE.jar ; spring-aop-3.2.6.jar

    spring-aop-3.2.6.RELEASE.jar ; spring-aop-3.2.6.jar spring面向切面编程需要导入的包

    Spring源码缺失的spring-cglib-repack-3.2.6.jar和spring-objenesis-repack-2.6.jar

    在Spring框架中,`spring-cglib-repack-3.2.6.jar`和`spring-objenesis-repack-2.6.jar`是两个重要的依赖库,它们在Spring源码环境中扮演着不可或缺的角色。本文将详细介绍这两个库以及它们在Spring框架中的作用。 ...

    wstx-asl-3.2.6.jar

    cxf与spring集成时需要用的jar包,wstx-asl-3.2.6.jar

    mybatis-3-mybatis-3.2.6

    MyBatis是一个优秀的Java持久层框架,它支持定制化SQL、存储过程以及高级映射。在深入探讨MyBatis 3.2.6版本的源码之前,我们首先需要了解MyBatis的基本概念和功能。 MyBatis的核心部分主要包括SqlSessionFactory、...

    apache-cxf-3.2.6.zip

    3. **JAX-WS和JAX-RS规范实现**:CXF实现了Java API for XML Web Services (JAX-WS)和Java API for RESTful Web Services (JAX-RS),使开发者能够遵循这些标准来开发Web服务。 4. **多种绑定机制**:CXF支持多种传输...

    spring-cglib-repack-3.2.6.jar,spring-objenesis-repack-2.6.jarspring-cglib-repack

    在给定的标题和描述中,提到了两个关键的jar包:`spring-cglib-repack-3.2.6.jar` 和 `spring-objenesis-repack-2.6.jar`。这两个文件对于理解Spring框架的内部机制以及如何在IDEA中构建Spring源码至关重要。 首先...

    alibaba-rocketmq-3.2.6 包

    3. **消息回溯**:在3.2.6版本中,RocketMQ提供了消息回溯功能,允许消费者在一段时间内重读已消费的消息,这对于故障恢复和审计跟踪非常有用。 4. **高可用性**:RocketMQ通过主备切换和分布式集群部署确保服务的...

    alibaba-rocketmq-3.2.6.tar.gz

    alibaba-rocketmq-3.2.6.tar.gzalibaba-rocketmq-3.2.6.tar.gzalibaba-rocketmq-3.2.6.tar.gzalibaba-rocketmq-3.2.6.tar.gzalibaba-rocketmq-3.2.6.tar.gz

    spring-framework-3.2.6.RELEASE

    Spring 3.2.6.RELEASE 是该框架的一个稳定版本,发布于2014年,提供了许多关键改进和增强。 一、Spring 框架的核心特性 1. 依赖注入(Dependency Injection,DI):Spring 框架通过 DI 实现组件之间的解耦,使得...

    spring-framework-3.2.6.RELEASE-dist.zip

    《Spring Framework 3.2.6.RELEASE:构建强大企业级应用的核心技术解析》 Spring Framework,作为Java领域最广泛使用的轻量级框架之一,以其模块化、灵活的架构设计和丰富的功能特性,赢得了广大开发者的一致好评。...

    mybatis-3-mybatis-3.2.6.zip

    标题中的"mybatis-3-mybatis-3.2.6.zip"指的是MyBatis框架的3.2.6版本源码的压缩包。这个版本发布于2014年,是MyBatis发展历史中的一个重要节点。MyBatis 3.x系列引入了许多改进和优化,提高了开发效率和性能。 ...

Global site tag (gtag.js) - Google Analytics