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'。对于这种扫描类型,只要记住前置列(或列集)的明显值越少,所需的逻辑子索引越少,则因此所要访问的总块数越少。
详细解决方案
《Pro Oracle SQL》Chapter3-3.2.6 Index Skip Scan
热度:214 发布时间:2016-05-05 14:06:10.0
相关解决方案
- 求教,SSH + ORACLE 日期处理有关问题
- hibernate 连接 oracle session 有关问题
- Spring自动扫描 <context:componet-scan>和加了<context:include-filter>以后有什么区别
- eclipse+tomcat6.0+oracle 10g配置数据库连接池的异常
- index.jsp经过模拟action接口 转发 到login.jsp页面后,页面背景无法显示
- java 生成 word 封存到 oracle 数据库
- oracle 最大连市接数 为什么main方法无限拿连接
- oracle 分页排序,ssi,该怎么处理
- oracle 最近的时间(而不是前一天的时间) 跪求sql语句 。解决方法
- java.sql.SQLException: No suitable driver found for jdbc:oracle:thin:192.168解决思路
- Parameter index out of range (五 > number of parameters, which is 4)
- java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver,该怎么处理
- 求高手看一看!index.jsp可以进,在往上点就出现有关问题了
- Jsp + Oracle 怎么取回id,报错getInt not implemented for class oracle.jdbc.driver.T4CRo
- oracle 调用java程序,该如何处理
- oracle,该怎么解决
- 在 Hibernate3 查询不到 Oracle 11g 里的记录
- tomcat启动出现Caused by: java.lang.StringIndexOutOfBoundsException: String index out解决方法
- JSP有关问题 index.jsp使用meta 页面都跳转不过去
- Oracle 评论排序!该怎么解决
- oracle 安装时出现 java tm 异常
- android访问其他数据库(如:oracle、MySql等),希望大家给点建议!解决方案
- oracle sql 有关问题
- oracle 安插 LONG VARCHAR 类型数据
- 小白请问: 关于 index.jsp 中 isValid() == false的异常。 就剩20分了.对不住各位了><
- jdbc+oracle 11中文乱码(英文一般)-在线盼
- ORACLE 一条SQL的有关问题
- oracle loadjava如何用
- java.lang.StringIndexOutOfBoundsException: String index out of range: 12
- netbeans desktop Application 连 Oracle 数据库的有关问题