- 浏览: 90344 次
- 性别:
- 来自: 深圳
文章分类
- 全部博客 (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--之三
Reading the Plan 解读计划 (page163)
Before I dive further into capturing actual execution plan data, I want to make sure you are
comfortable with reading a plan. I’ve already discussed the importance of the PARENT_ID column in
making it easier for you to break a long, complex plan down into smaller, more manageable sections.
Breaking a plan down into smaller chunks will help you read it, but you need to know how to approach
reading a whole plan from start to finish.
在我深入讲解实际执行计划之前,我想确认你有自信解读计划。我已经讨论了用PARENT_ID列将一个长而复杂的计划分解成小段可管理段的重要性。将计划分解成小块有利于你读它,但是你(更)需要知道如何从头到尾解读整个计划。
There are three ways that will help you read and understand any plan: 1) learn to identify and
separate parent-child groupings, 2) learn the order in which the plan operations execute, and 3) learn
to read the plan in narrative form. I have learned to do these three things so that when I look at a plan, my eye moves through the plan easily and I notice possible problem areas quickly. It can be
frustrating and a bit slow at first, but given time and practice, it will become second nature.
有三种方法帮助你解读和理解任何计划:1)学会标示和分离父-子组。2)学会(查看)计划操作执行的顺序。3)学会用叙述的形式解读计划。我掌握了这三种
方法,所以当我看一个计划时,我的眼睛能轻松的扫视计划,迅速的定位可能的问题区域。刚开始的时候肯定会有些郁闷和慢,但是假以时日不断的练习,就成了习
惯。
The first place to start is with execution order. The plan is displayed in order by the sequential ID
of operations. However, the order in which each operation executes isn’t accomplished in a precise
top-down fashion. Using the visual cues of the indentation of the operations, you can quickly scan a
plan and look for the operations that are the most indented. The operation that is most indented is
actually the first operation that will be executed. If there are multiple operations at that same level, the operations are executed in a top-down order.
第一步是从执行顺序入手。计划是根据操作的序列ID展示的。然而,每一步操作的执行顺序不完全按照从上到下的风格排列。通过操作的缩进的视觉线索,你能快
速的扫描一个计划,查找缩进最深的操作。缩进最深的操作实际上是最先执行的。如果有多个操作具有相同的(缩进)级别,将按照从上到下的顺序执行。
For reference, I’m going to re-list the example plan here in Listing 6-5 so that you don’t have to
flip back a few pages to the original example in Listing 6-1.
为了引述方便,我重新把例子计划列在列表6-5中,你就不需要翻回前面几页找原来在列表6-1中的例子。
Listing 6-5. EXPLAIN PLAN Example (Repeated)
-----------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)|
-----------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 106 | 11872 | 13 (16)|
|*
1 | HASH JOIN
| | 106 | 11872 | 13 (16)|
|*
2 | HASH JOIN
| | 27 | 1917 | 10 (20)|
| 3 | NESTED LOOPS | | 27 | 1539 | 6 (17) |
|
4 | MERGE JOIN
| | 27 | 1134 | 6 (17) |
| 5 | TABLE ACCESS BY INDEX ROWID | DEPARTMENTS | 27 | 513 | 2 (0) |
| 6 | INDEX FULL SCAN | DEPT_LOCATION_IX | 27 | | 1 (0) |
|*
7 | SORT JOIN
| | 23 | 529 | 4 (25) |
| 8 | TABLE ACCESS FULL | LOCATIONS | 23 | 529 | 3 (0) |
|* 9 | INDEX UNIQUE SCAN | COUNTRY_C_ID_PK | 1 | 15 | 0 (0) |
| 10 | TABLE ACCESS FULL | REGIONS | 4 | 56 | 3 (0) |
| 11 | TABLE ACCESS FULL | EMPLOYEES | 107 | 4387 | 3 (0) |
-----------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - access("E"."DEPARTMENT_ID"="D"."DEPARTMENT_ID")
2 - access("C"."REGION_ID"="R"."REGION_ID")
7 - access("D"."LOCATION_ID"="L"."LOCATION_ID")
filter("D"."LOCATION_ID"="L"."LOCATION_ID")
9 - access("L"."COUNTRY_ID"="C"."COUNTRY_ID")
At a glance, you can see that lines 6 and 8 are the most deeply indented. Line 6 will execute first
and pass the rowids from the index full scan to its parent (line 5). Line 8 will execute next and pass its row source to its parent (line 7). Steps will continue to execute from most indented to least indented with each step passing row source data to its parent until all steps complete. In order to help see the execution order more clearly, Listing 6-6 executes a query similar to the query used in Listing 6-3 that reads from the P LAN_TABLE and orders the output in execution order.
第一眼,你就能看出第6,8行缩进的最深。第6行最先执行,把全盘索引扫描的rowid传递给它的上一级。第8行接着执行,把它的行源传递给它的上一
级。(操作)步骤由里向外,每一步都将行源传递给它的上一步,直到所有步骤完成。为了让执行顺序看的更清楚。列表6-6执行了同列表6-3相似的查询,读
取PLAN_TABLE按执行顺序排序输出。
Listing 6-6. Plan Operations Displayed in Execution Order 按执行顺序显示计划操作
SQL>select id, parent_id, operation
2 from (
3 select level lvl, id, parent_id, lpad(' ',level) || operation || ' ' || options
4 || ' ' || object_name as operation
5 from plan_table
6 start with id = 0
7 connect by prior id = parent_id
8 )
9 order by lvl desc, id;
ID PARENT_ID OPERATION
---------- ---------- --------------------------------------------------
6 5 INDEX FULL SCAN DEPT_LOCATION_IX
8 7 TABLE ACCESS FULL LOCATIONS
5 4 TABLE ACCESS BY INDEX ROWID DEPARTMENTS
7 4 SORT JOIN
4 3 MERGE JOIN
9 3 INDEX UNIQUE SCAN COUNTRY_C_ID_PK
3 2 NESTED LOOPS
10 2 TABLE ACCESS FULL REGIONS
2 1 HASH JOIN
11 1 TABLE ACCESS FULL EMPLOYEES
1 0 HASH JOIN
0 SELECT STATEMENT
I often use an analogy between parent-child relationships in a plan and real life parent-child
relationships. A real child doesn’t just spontaneously combust into being; a parent is required to
“instantiate” the child into being. But, like most any parent will tell you, one of the greatest things
about kids is that (sometimes) you can get them to do work for you. This applies to parent-child
operations in a plan. The child takes direction from its parent and goes to do a piece of work. When
the child completes that work, it reports back to the parent with the result. So, even though an index
operation occurs before its parent (for example, step 6 executes before its parent in step 5), the child
wouldn’t have meaning or existence without its parent. This is why it’s important to always keep the
parent-child relationships in mind as it helps make sense of the execution order.
我经常拿计划中的父子关系同现实生活中的父子关系做类比。实际中的“子”不会自发而存在,而是需要由“父”先初始化“子”(子才能用)。但是,像大多数父
亲告诉你的,关于小孩最了不起的事情就是你可以让他为你打酱油。这同样适用于计划操作中的父子关系。“子”从“父”获得指令,做一小部分工作。当“子”完
成工作,它返回给“父”结果。这样,即使一个索引操作发生在它的“父”之前(例如,第6步执行在它的“父”第5步之前),“子”没有“父”就没有意义,或
者不能存在。这就是为什么总是铭记父子关系是如此重要,有助于你理解执行顺序。
One of the most helpful sections of the explained output is the section named Predicate
Information. In this section, the ACCESS_PREDICATES and FILTER_PREDICATES columns are displayed. These columns are associated with a line (denoted by the ID column) in the list of plan operations. You’ll notice that for each plan operation that has an access or filter predicate associated with it, there is an asterisk (*) next to the ID. When you see the asterisk, you know to look for that ID number in the Predicate Information section to see which predicate (condition in the WHERE clause) was related to that operation. Using this information you can confirm that columns were correctly (or not) used for index access and also to determine where a condition was filtered.
解释输出最有帮助的一段就是被称之为谓词信息的那段。在该段中有展示ACCESS_PREDICATES和FILTER_PREDICATES列。这些列
关联操作计划列表中的行号(标记成ID列)。你可以注意到每一个执行计划操作都有一个访问或者过滤谓词关联着它,这是挨着ID的星号(*)。当你看到星
号,通过查找在谓词信息中的ID号去看(在WHERE子句的条件中)哪个谓词关联到了那个操作。用这个信息你能确认那些列是否正确的使用了索引访问且判断
条件在哪过滤的。
Filtering late is a common performance inhibitor. For example, if you wanted to move a pile of 100
rocks from the front yard to your back yard but only needed rocks that weighed 5-10 pounds, would you want to move all 100 rocks and then remove the ones you needed, or would you simply want to carry the ones that were the correct weight? In general, you’d want to only take the rocks you need, right?
“晚”过滤通常是性能的阻化剂。例如,如果你想搬1堆100块的石头,从你的前院到后院,但是你想要的石块重量大约5-10磅。你将搬动所有的100块(到后院),再取出你需要的?还是只是简单的搬动你想要重量的石块?一般而言,你只是搬动你需要的,对吧?
Using the filter predicate information can help you verify that unneeded rows are filtered out of
your result set as early as possible in the plan. Just like it wouldn’t make much sense to carry a whole
bunch of extra rocks to the back yard, it wouldn’t make much sense to carry rows through a whole set of plan operations that ultimately will not be included in the final result set. You will use the filter
information to verify that each condition is applied as early in the plan as possible. If a filter is applied
too late, you can adjust your SQL or take other steps (like verifying statistics are up to date) to ensure
your plan isn’t working harder than it needs to.
使用过滤器谓词信息能帮助你确认结果集中不需要的行是否尽可能早的在计划中就过滤了。就好像你通常不会搬动而外的石块去后院一样,也通常不会搬动最终不包
含在结果集的行贯穿整个计划操作。你将用过滤信息确认每一个条件在计划中应用的越早越好。如果过滤器应用的太晚,你能调整你的SQL或者采用其他的步骤
(像确认统计是否最新)来确保你的计划是否做了很多垃圾工作。
Finally, learning to read the plan as if it were a narrative can be extremely helpful. For many
people, converting the set of plan operations into a paragraph of text can facilitate understanding how the plan executes better than any other method. Let’s convert your example plan into a narrative and see if it makes it easier for you to read and understand. The following paragraph is a sample narrative for the example plan.
最后,学会解读计划成记叙(文)将是非常有帮助的。对于许多人来说,把一套计划操作转换成一段文本,相比其他方法而言,能够更容易理解计划操作是如何执行的。让我转换例子计划成一段记叙文,看是否更容易让你读和理解。下面一段就是例子计划的简单记叙文。
In order to produce the result set for this SELECT statement, rows from the DEPARTMENTS table
will be accessed utilizing a full scan of the index on the DEPARTMENTS.LOCATION_ID column.
Using a full scan of the LOCATIONS table, rows will be retrieved and sorted by LOCATION_ID and
then merged with the rows from DEPARTMENTS to produce a joined result set of matching rows
containing both DEPARTMENTS and LOCATIONS data. This row set, which I’ll call DEPT_LOC, will be
joined to the COUNTRIES table and will iteratively match one row from DEPT_LOC using the
COUNTRY_ID to find a matching row in COUNTRIES. This result set, which I’ll call DEPT_LOC_CTRY,
now contains data from DEPARTMENTS, LOCATIONS, and COUNTRIES and will be hashed into
memory and matched with the REGIONS table data using the REGION_ID. This result set,
DEPT_LOC_CTRY_REG, will be hashed into memory and matched with the EMPLOYEES table using
the DEPARTMENT_ID to produce the final result set of rows.
为了生成这条SELECT语句的结果集,将通过全扫描在DEPARTMENTS.LOCATION_ID列的索引访问DEPARTMENTS表的行。使用全扫描LOCATIONS表得到的行集用LOCATION_ID排序,且同来自DEPARTMENTS的行集融合,生成一连接的匹配行集,包含
DEPARTMENTS和LOCATIONS数据。我把这个行集称之为DEPT_LOC,将用来连接COUNTRIES表。通过COUNTRY_ID在
CONTRIES找到匹配的行,迭代匹配
DEPT_LOC中的行。这个行集称之为
DEPT_LOC_CTRY, 它包含来至
DEPARTMENTS, LOCATIONS, 和COUNTRIES 的数据。将哈希入内存再通过REGION_ID匹配来至REGIONS表的数据。得到结果集
DEPT_LOC_CTRY_REG,再次被哈希,再通过
DEPARTMENT_ID匹配EMPLOYEES表生成最终的结果集。
To produce this narrative, I simply walk through the steps of the plan in execution order and write
out the description of the steps and how they link (join) to each other. I progress through each set of
parent-child operations until all the steps are complete. You may find that creating a narrative helps
you grasp the overall plan with a bit more clarity. For more complex plans, you may find that breaking
out just a few key portions of the whole plan and writing it out in narrative form will help you better
understand the flow of operations. The key is to use the narrative to help make better sense of the
plan. If you find it harder to do this, then just stick with the plan as it is. But, taking time to learn to
convert a plan into a narrative form is a good skill to learn as it can help you describe what your query
is doing in a way that doesn’t require anyone even looking at plan output. It’s similar to giving verbal
directions on how to get to the nearest shopping mall. You don’t necessarily have to have the map to
be able to get from point A to point B.
为了生成这段记叙文,我简单的按执行顺序过了一遍步骤,写出每步的描述,以及他们之间如何连接的。我梳理每一组父子关系直到所有的步骤完成。你将发现创建
一篇记叙文对于你非常清晰的掌握整篇计划是非常有帮助的。越复杂的计划,你会发现,将其分解成几个关键的部分,然后写成记叙文将使你更好的理解操作流程。
关键是使用记叙文能让你更好的理解计划。如果你发现这样做本身就很烦,那还不如直接看计划。但是花时间学会转换计划成记叙文是一个好的技能。因为它能帮你
描述你的查询做什么,而不需要其他人去看计划输出。就如同给出一口头指令,如何到达最近的超市。你没有必要有一张地图才能从A点走到B点。
发表评论
-
JavaBean学习三
2012-09-26 22:57 106032.4 Java Event Model Revie ... -
JavaBean 学习二
2012-09-21 00:07 94132.3 Bean Properties ... -
JavaBean 学习一
2012-09-19 00:09 129632.1 Introduction Eve ... -
《Pro Oracle SQL》 读书笔记--Chapter 6--6.2 Execution Plans--之五
2011-11-06 14:11 1140Using Plan Information for Solv ... -
《Pro Oracle SQL》 读书笔记--Chapter 6--6.2 Execution Plans--之四
2011-10-31 23:34 1132Understanding DBMS_XPLAN in Det ... -
《Pro Oracle SQL》--Chapter 6--6.2 Execute Plans--之三
2011-10-26 22:42 884Identifying SQL Statements for ... -
《Pro Oracle SQL》--Chapter 6--6.2 Execution Plans--之二
2011-10-25 07:11 999Collecting the Plan Statistics ... -
《Pro Oracle SQL》--Chapter 6 SQL Execution Plans --6.2 Execution Plans--之一
2011-10-22 10:17 1015Execution Plans 执行计划 (page 1 ... -
《Pro Oracle SQL》--Chapter 6--6.1 Explain Plans--之二
2011-10-17 23:06 1099Understanding How EXPLAIN PLAN ... -
《Pro Oracle SQL》--Chapter 6--6.1 Explain Plans--之一
2011-10-17 15:14 1083Chapter 6--SQL Execution Plans ... -
《Pro Oracle SQL》--chapter 5--5.6 Building Logical Expressions
2011-10-16 01:04 13945.6 Building Logical Expresions ... -
《Pro Oracle SQL》--Chapter 5--5.5 Questions about Data
2011-10-15 00:42 759Questions about Data 关于数据的问题 ... -
《Pro Oracle SQL》--Chapter 5--5.4 Questions about the Question
2011-10-12 00:36 12405.4 Questions about the Questio ...
相关推荐
《Pro Oracle SQL》是Oracle数据库查询优化的经典之作,第六章主要聚焦在Execution Plans(执行计划)上,这是数据库查询性能优化的关键。本章节的第四部分深入探讨了如何理解和解析执行计划,以及它对SQL性能的影响...
《Pro Oracle SQL》一书的第10章深入探讨了SQL优化,特别是10.2节,重点关注如何测试执行计划,这是SQL性能调优的关键环节。在这个部分,作者旨在帮助读者理解如何有效地评估和改进SQL查询的性能,以提高数据库系统...
《Pro Oracle SQL Development》这本书是Oracle SQL开发的专业指南,它深入探讨了Oracle数据库系统中的SQL语言使用和优化。Oracle SQL是用于管理和操作Oracle数据库的强大工具,对于任何在Java开发中涉及Oracle...
《X-Pack SQL JDBC驱动在Elasticsearch中的应用与详解》 Elasticsearch作为一个强大的开源搜索引擎,广泛应用于数据存储和检索领域。为了方便开发者利用传统SQL语法进行查询操作,Elasticsearch引入了X-Pack SQL ...
《Pro Oracle SQL》是Oracle SQL领域的一本权威指南,尤其针对11gR2版本进行了深入探讨。本书全面覆盖了Oracle SQL的各种概念、语法和高级特性,旨在帮助读者从初级到高级逐步提升对Oracle数据库查询语言的理解和...
《Pro Oracle SQL 2》是面向数据库管理员(DBA)和Oracle开发人员的专业SQL指南,第二版的内容在原基础上进行了更新和扩充,旨在提供更深入、更全面的Oracle SQL使用技巧和最佳实践。这本书深入探讨了Oracle SQL的...
《Pro Oracle SQL》是Oracle数据库查询的一本权威指南,其中第二章主要讲解SQL查询的高级技巧。在2.8节“子查询展开(Subquery Unnesting)”中,我们将会深入探讨Oracle SQL中一种优化查询性能的重要策略。这一部分...
《Pro Oracle SQL》是Oracle数据库查询优化的一本权威著作,其中第三章着重讲解了全面扫描(Full Scan Access Methods)这一重要的访问方法。在数据库查询优化中,了解并掌握不同的访问方法对于提高SQL查询性能至关...
### Oracle SQL Tuning详解 #### 一、Oracle SQL性能调优概述 在Oracle数据库管理中,SQL性能调优是一项至关重要的任务,它直接影响到应用程序的响应时间和系统的整体性能。SQL性能调优通常涉及对SQL语句进行分析...
《Oracle Press - Oracle Database 11g SQL》是专门针对Oracle数据库系统中SQL语言的一本详细教程,适合数据库管理员(DBA)、开发人员以及对Oracle SQL感兴趣的初学者学习。本书全面覆盖了Oracle 11g版本中的SQL...
"Oracle SQL Performance Tuning 39Tips" 提供了由Oracle专家Tom Kyte精心总结的30个SQL优化技巧,这些技巧旨在帮助用户提升数据库查询速度,减少资源消耗,提高系统整体性能。 1. **索引优化**:Tom Kyte强调了...
### ORACLE-SQL性能优化大全知识点详述 #### 一、优化基础知识概述 - **性能管理**: - **尽早开始**:性能优化应该在项目的早期就开始考虑,而不是等到后期出现性能瓶颈时才去处理。 - **设立合适目标**:设定...
- 解决慢查询:针对耗时较长的SQL语句,使用EXPLAIN PLAN分析执行计划,优化索引或重构查询语句。 7. **学习与实践**: - 学习如何正确解读STATSPACK报告,理解各种性能指标的含义。 - 实战演练,模拟性能问题并...
《Oracle相关SQL葵花宝典》是一本专为学习Oracle数据库管理系统中SQL语言及PL/SQL编程设计的综合指南。本书全面涵盖了从基础到高级的Oracle SQL知识,旨在帮助读者熟练掌握在Oracle环境中进行数据查询、操作、分析...
Oracle SQL优化是数据库管理员和开发人员提升系统性能的关键技能。Oracle数据库系统因其高效、稳定和功能强大而被广泛使用,但随着数据量的增长,SQL查询的优化变得至关重要。本资源"Oracle_SQL优化.PDF"虽然内容...
1. 使用EXPLAIN PLAN分析查询:Oracle提供EXPLAIN PLAN工具,用于分析SQL执行计划,帮助找出潜在的性能瓶颈。 2.绑定变量:使用绑定变量可以减少硬解析,提高SQL执行效率。 3. 优化连接顺序:JOIN操作中,优化连接...
Oracle PL/SQL是Oracle数据库系统中的重要组成部分,用于创建复杂的业务逻辑和数据库处理。以下是对题目中提到的一些关键知识点的详细解释: 1. **冷备份与热备份**:冷备份是在数据库关闭状态下进行的,简单且可靠...
Oracle SQL疑难解析是一本专为解决数据库操作中遇到的实际问题而编写的书籍,它涵盖了大量SQL查询、数据处理和性能优化的实用技巧。在"oracle-sql-recipes-master"这个压缩包中,很可能是包含了书中的示例代码和练习...
Oracle Instant Client是Oracle公司提供的一款轻量级的数据库连接工具,它允许用户在不安装完整Oracle数据库的情况下,进行Oracle数据库的连接、查询和管理。在本案例中,我们讨论的是Oracle Instant Client的11.2...
Oracle SQL编写规范 Oracle SQL编写规范是指在编写SQL语句时的一些基本原则和方法,旨在提高SQL语句的执行效率和可读性。以下是Oracle SQL编写规范的详细解释: 1. 尽量用索引,特别在从大量数据中返回小部分数据...