- 浏览: 90312 次
- 性别:
- 来自: 深圳
文章分类
- 全部博客 (81)
- 读书笔记 (14)
- NetBeans学习 (1)
- JavaBeans and Bean Events (3)
- 《Pro Oracle SQL》Chapter 2 SQL Execution (13)
- 《Pro Oracle SQL》Chapter 3 Access and Join Methods (16)
- Pro Oracle SQL Chapter 5 (0)
- Pro Oracle SQL Chapter 6 (0)
- Pro Oracle SQL Chapter 7 (9)
- Pro Oracle SQL Chapter 8 (9)
- 《Pro Oracle SQL》Chapter 9 The Model Clause (11)
- 《Pro Oracle SQL》Chapter 10 Subquery Factoring (7)
最新评论
-
mojunbin:
这个不能不顶。
《Pro Oracle SQL》 Chapter2--2.1 Oracle Architecture Basics -
Branding:
谢谢,获益匪浅
《Pro Oracle SQL》--chapter 5--5.6 Building Logical Expressions -
Branding:
《Pro Oracle SQL》--Chapter 5--5.4 Questions about the Question -
Branding:
谢谢
《Pro Oracle SQL》 翻译序 -- 读书心得 -
jiaoshiguoke:
继续 加油
《Pro Oracle SQL》--Chapter 6--6.1 Explain Plans--之三
《Pro Oracle SQL》Chapter 3--3.2.5 Index Full Scan
Index Full Scan 索引全扫描
(page 103)
An index full scan is chosen under several conditions including: when there is no predicate but the
column list can be satisfied through an index on a column, the predicate contains a condition on a
non-leading column in an index, or the data can be retrieved via an index in sorted order and save the
need for a separate sort step. Listing 3-13 shows an example of each of these cases.
选中索引全扫描包括下列几种条件:没有谓词但是可通过列上的索引满足(查询)列集,谓词包含一个在索引中非前置列上的条件,或者数据能通过索引按顺序检索而省去了单独排序的步骤。
Listing 3-13. Index Full Scan Examples
SQL> set autotrace traceonly explain
SQL> select email from hr.employees ;
--HR EMP_EMAIL_UK Unique EMAIL
Execution Plan
----------------------------------------------------------
Plan hash value: 2196514524
----------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)|
----------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 107 | 856 | 1 (0) |
| 1 | INDEX FULL SCAN | EMP_EMAIL_UK
| 107 | 856 | 1 (0) |
----------------------------------------------------------------------
SQL>
SQL> select first_name, last_name from hr.employees
2 where first_name like 'A%' ;
--HR EMP_NAME_IX Normal LAST_NAME, FIRST_NAME
Execution Plan
----------------------------------------------------------
Plan hash value: 2228653197
---------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)|
---------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 3 | 45 | 1 (0) |
|* 1 | INDEX FULL SCAN | EMP_NAME_IX
| 3 | 45 | 1 (0) |
---------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - access("FIRST_NAME" LIKE 'A%')
filter("FIRST_NAME" LIKE 'A%')
SQL> select * from hr.employees order by employee_id ;
Execution Plan
----------------------------------------------------------
Plan hash value: 2186312383
----------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)|
----------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 107 | 7276 | 3 (0) |
| 1 | TABLE ACCESS BY INDEX ROWID | EMPLOYEES | 107 | 7276 | 3 (0) |
| 2 | INDEX FULL SCAN | EMP_EMP_ID_PK
| 107 | | 1 (0) |
----------------------------------------------------------------------------------
SQL> select * from hr.employees order by employee_id desc ;
Execution Plan
----------------------------------------------------------
Plan hash value: 2761389396
----------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)|
----------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 107 | 7276 | 3 (0) |
| 1 | TABLE ACCESS BY INDEX ROWID | EMPLOYEES | 107 | 7276 | 3 (0) |
| 2 | INDEX FULL SCAN DESCENDING
| EMP_EMP_ID_PK
| 107 | | 1 (0) |
----------------------------------------------------------------------------------
An index full scan operation will scan every leaf block in the index structure, read the rowids for
each entry, and retrieve the table rows. Every leaf block is accessed. This is often more efficient than
doing a full table scan as the index blocks will contain more entries than the table blocks will,
therefore fewer overall blocks may need to be accessed.
In cases where the columns needed to satisfy
the column list are all present as part of the index entry, the table access step is avoided as well.
This
means that choosing an index full scan operation will be more efficient than reading all the table
blocks.
索引全扫描操作将扫描在索引结构中的每个叶块,读取每条记录的rowid,检索表的行集。每个叶块都被访问到。这通常都比做全表扫描更加有效率因为索引块比表块包含更多的记录。因此总体上需要访问的块要少一些。
如果列集中所需的列都是索引记录的一部分,还可以省略表访问步骤。
这意味着选择索引全扫描操作将比读取所有表块更有效率。
You may have noticed in the last example that the index full scan operation also has the ability to
read in descending order to avoid the need for a separate descending ordered sort request. There is
another optimization for index full scans. This optimization occurs when a query requests the
minimum or maximum column value and that column is indexed. Listing 3-14 shows an example of
this operation choice.
你可能注意到在上个例子中索引全扫描操作能降序读入而避免需要单独的降序排序请求。索引全扫描还有另一个优化。当查询请求某具有索引的列上的最小或最大列值时,这个优化就会发生。列表3-14展示了这个操作选择的例子。
Listing 3-14. Index Full Scan Min/Max Optimization
SQL> set autotrace traceonly explain
SQL> select min(department_id) from hr.employees ;
--HR EMP_DEPARTMENT_IX Normal DEPARTMENT_ID
Execution Plan
----------------------------------------------------------
Plan hash value: 613773769
-------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)|
-------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 3 | 3(0) |
| 1 | SORT AGGREGATE | | 1 | 3 | |
| 2 | INDEX FULL SCAN (MIN/MAX)
| EMP_DEPARTMENT_IX | 107 | 321 | |
-------------------------------------------------------------------------------------
SQL> select max(department_id) from hr.employees ;
Execution Plan
----------------------------------------------------------
Plan hash value: 613773769
-------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)|
-------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 3 | 3 (0) |
| 1 | SORT AGGREGATE | | 1 | 3 | |
| 2 | INDEX FULL SCAN (MIN/MAX)
| EMP_DEPARTMENT_IX | 107 | 321 | |
-------------------------------------------------------------------------------------
SQL> select min(department_id), max(department_id) from hr.employees ;
Execution Plan
----------------------------------------------------------
Plan hash value: 1756381138
---------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)|
---------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 3 | 3 (0) |
| 1 | SORT AGGREGATE | | 1 | 3 | |
| 2 | TABLE ACCESS FULL | EMPLOYEES | 107 | 321 | 3 (0) |
---------------------------------------------------------------------
SQL> select (select min(department_id) from hr.employees) min_id,
2 (select max(department_id) from hr.employees) max_id
3 from dual
4
Execution Plan
----------------------------------------------------------
Plan hash value: 2189307159
-------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)|
-------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | | 2 (0)|
| 1 | SORT AGGREGATE | | 1 | 3 | |
| 2 | INDEX FULL SCAN (MIN/MAX)| EMP_DEPARTMENT_IX | 107 | 321 | |
| 3 | SORT AGGREGATE | | 1 | 3 | |
| 4 | INDEX FULL SCAN (MIN/MAX)| EMP_DEPARTMENT_IX | 107 | 321 | |
| 5 | FAST DUAL | | 1 | | 2 (0)|
-------------------------------------------------------------------------------------
As the example shows, when a MIN or MAX aggregate is requested, the optimizer can choose a special optimized version of the index full scan operation. In these special cases, when the index is used to quickly retrieve the minimum value, it will be the first entry in the first index leaf block; when it
retrieves the maximum value, it will be the last entry in the last index leaf block. This makes perfect
sense as the index is stored in sorted order so the minimum and maximum values have to be at either
end of the first and last leaf blocks.
But the really great part is that in these special cases, the index full
scan isn’t really a full scan—it is a scan of only root block, one or more branch blocks, and first or last
leaf blocks. This means that finding these values is very fast and very low cost in terms of the number
of block accesses required. While the index full scan operation title may make it seem a bit confusing
as index full scans typically read all the index leaf blocks, this optimization is a nice win
in terms of
performance.
如例子所示,当请求MIN和MAX聚合函数,优化器就能选择特别优化版的索引全扫描操作。在这些特殊的案例中,当索引用于快速检索最小值,它将是第一个索引叶块的第一条记录;当它检索的是最大值,它将是最后索引叶块的最后一条记录。这真是很完美,因为索引是按顺序存入的所以最小值、最大值必然在第一个和最后一个叶块的两端。
但是在这些特殊案例中真正了不起的地方是:索引全扫描实际不是全扫描--它只扫描了根块,一个或多个分支块,还有第一个或最后一个叶
块。这就是说找到这些值是非常的快和成本低的,根据所需访问的块数而言。虽然索引全扫描操作标题可能让它似乎有些迷惑,因为索引全扫描一般都是读取所有的索引叶块,这个优化是性能上的美好胜利
。
I did include an example of where the query included both a MIN and a MAX aggregate, and as you
may have noticed, the optimizer chose to do a full table scan with a sort instead of the nice optimized
index full scan operation. While I think this is a short-coming
in the way the optimizer handles this
situation, there is a fairly easy way to get the same optimized behavior. Just code the two queries
separately. In this way, you get the benefits of the optimization.
我包含了一个例子,查询中同时包含一个MIN和一个MAX聚合,而你可能注意到,优化器选择的是带排序的全表扫描,而不是精密优化的索引全扫描操作。虽然我想这是优化器处理这种情况的一个缺点
,但是很容易取得相同的优化行为。只要写两个单独的查询。这样,你就能受益于该优化。
发表评论
-
《Pro Oracle SQL》Chapter3 -- 3.3.5 Outer Joins
2012-04-02 11:41 1279Outer Joins 外连接 (p ... -
《Pro Oracle SQL》Chapter 3 -- 3.3.4 Cartesian Joins
2012-04-01 02:14 1033Cartesian Joins 笛卡尔连接 ... -
《Pro Oracle SQL》Chapter 3 -- 3.3.3 Hash Joins
2012-03-30 02:15 1038Hash Joins 哈希连接 (pa ... -
《Pro Oracle SQL》Chapter 3 -- 3.3.2 Sort-Merge Joins
2012-03-27 22:07 1021Sort-Merge Joins 排序-合并连接 ... -
《Pro Oracle SQL》Chapter 3 -- 3.3.1 Nested Loops Joins
2012-03-25 18:12 1055Nested Loops Joins 嵌套循环连接 ... -
《Pro Oracle SQL》Chapter 3 -- 3.3 Join Methods
2012-03-24 15:51 1032Join Methods 连接方法 ... -
《Pro Oracle SQL》Chapter3--3.2.7 Index Fast Full Scan
2012-03-24 01:09 1543Index Fast Full Scan 索引快速全扫描 ... -
《Pro Oracle SQL》Chapter3--3.2.6 Index Skip Scan
2012-03-23 00:57 1152Index Skip Scan 索引跳跃扫描 ... -
《Pro Oracle SQL》Chapter3--3.2.4 Index range scan
2012-03-20 00:10 1046Index range scan 索引范围扫描 ... -
《Pro Oracle SQL》Chapter3--3.2.3 Index Unique Scan
2012-03-19 05:26 989Index Unique Scan 索引 ... -
《Pro Oracle SQL》Chapter3--3.2.2 Index Scan Types
2012-03-17 23:34 1037Index Scan Types 索引扫描 ... -
《Pro Oracle SQL》Chapter3--3.2 Index Scan Access Methods--3.2.1 Index Structure
2012-03-15 20:04 965Index Scan Access Methods ... -
《Pro Oracle SQL》Chapter3--3.1.4 Full Scans and the Highwater Mark
2012-03-14 20:49 965Full Scans and the Highwater Ma ... -
《Pro Oracle SQL》Chapter3--3.1 Full Scan Access Methods 之二
2012-03-11 23:14 940Full Scans and Throwaway 全扫描和“ ... -
《Pro Oracle SQL》Chapter3--3.1Full Scan Access Methods之一
2012-03-10 18:01 939Chapter3 Access and Join Metho ...
相关推荐
apache-maven-3.2.5.zip 安装包,apache-maven-3.2.5.zip 安装包apache-maven-3.2.5.zip 安装包apache-maven-3.2.5.zip 安装包apache-maven-3.2.5.zip 安装包apache-maven-3.2.5.zip 安装包apache-maven-3.2.5.zip ...
3. **Maven的插件**: Maven通过插件机制执行各种任务,如编译、测试、打包、部署等。在"META-INF"目录下,我们可以看到Maven的插件配置信息。例如,`maven-compiler-plugin`用于Java源代码的编译,`maven-surefire...
spring-aop-3.2.5.RELEASE.jar
"apache-maven-3.2.5" 提供了 Maven 3.2.5 版本的完整包,它包含了构建和管理Java项目所需的所有组件。这个版本在当时是一个稳定且广泛使用的版本,对于理解 Maven 的工作原理和使用方式具有重要意义。 Maven 的...
在下载的"apache-maven-3.2.5-bin"压缩包中,通常包含以下内容: 1. `bin`目录:包含了可执行的命令行工具,如`mvn`,用于执行Maven命令。 2. `conf`目录:包含Maven的配置文件,比如`settings.xml`,它是Maven的...
3. **生命周期与构建阶段**:Maven有预定义的构建生命周期,如`clean`、`default`和`site`,它们包含了多个阶段,如`compile`、`test`、`install`和`deploy`。开发者可以通过简单的命令如`mvn clean install`来执行...
Maven是基于项目对象模型(POM),可以通过一小段描述信息来管理项目的构建,报告和文档的软件项目管理工具。 Maven 除了以程序构建能力为特色之外,还提供高级项目管理工具。由于 Maven 的缺省构建规则有较高的可重用...
"apache-maven-3.2.5-bin.tar.gz"是Apache Maven 3.2.5版本的二进制发行包,采用tar.gz格式进行压缩,适用于Unix/Linux类操作系统。 Maven的核心概念之一是项目对象模型(Project Object Model,POM)。POM是一个...
而`spring-cglib-repack-3.2.5.jar`和`spring-objenesis-repack-2.6.jar`这两个文件是Spring框架中两个重要的依赖包,它们分别涉及到CGlib和Objenesis两个库,这两个库在Spring中的作用不可小觑。 **CGlib(Code ...
"spring-cglib-repack-3.2.5.jar"、"spring-objenesis-repack-2.6.jar"和"spring-objenesis-repack-2.5.1.jar"这三个文件是Spring源码阅读环境中常用的依赖包,它们各自承担着不同的功能。 首先,我们来看"CGLIB"...
`apache-maven-3.2.5-bin.zip` 是Apache Maven 3.2.5版本的二进制发行包,包含了运行Maven所需的所有文件。 1. **Maven简介**: Maven通过使用一种标准化的项目对象模型(Project Object Model, POM)来描述项目,并...
Maven 3.2.5是该工具的一个版本,发布于2014年,旨在提高构建效率,增强稳定性,并修复了前一版本的一些已知问题。 在Java开发中,Maven通过使用一个统一的构建生命周期和约定优于配置的原则,极大地简化了项目构建...
2017-11-05从git_hub上拉取的Spring源码打成的jar,构建Spring-beans源码所缺失的两个jar包spring-cglib-repack-3.2.5.jar,spring-objenesis-repack-2.5.1.jar