- 浏览: 90678 次
- 性别:
- 来自: 深圳
文章分类
- 全部博客 (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》CHAPTER2--2.7 View Merging
View Merging 视图合并
(Page 62)
As the name implies, view merging is a transformation that expands views, either in-line views or stored views, into separate query blocks that can either be analyzed separately or that can be merged with the rest of the query to form a single overall execution plan.
Basically, the statement is rewritten without the view. A statement like select * from my_view would be rewritten as if you had simply typed in the view source. View merging usually occurs when the outer query block’s predicate contains:
正如名字所暗示的,视图合并是一种变换:扩展视图,要么是内联视图要么是存储的视图,成独立的查询块能够被分别分析或者能同查询的其余部分合并而形成一整体执行计划。
基本上,语句被重写成没有视图了,如同select * from
my_view这样的语句将被重写的像你直接在视图源输入的一样。视图合并通常发生在外部查询块的谓词包含:
- a column that can be used in an index within another query block.
- a column that can be used for partition pruning within another query block.
- a condition that limitis the rows returned from one of the tables in a joined view.
- 有一列能被其他的查询块中的索引所使用。
- 有一列能被其他的查询块中的分区裁剪所使用。
- 有一条件限制在连接的视图中某张表的返回行数。
Most people believe that a view will always be treated as a separate query block and will always have
its own subplan and be executed prior to joining to other query blocks. That is not true due to the
actions of the query transformer. The truth is that sometimes views will be analyzed separately and have
their own subplan, but more often than not, merging views with the rest of the query provides a greater
performance benefit. For example, the following query might use resources quite differently depending
on whether or not the view is merged:
大多数人相信视图将总是被作为分散的查询块对待,且总是有它自己的子计划,也在先于连接到其他查询块之前执行。这是不对的,因为查询变换的作用。事实是有时视图将被独立的分析且有他自己的子计划,但是往往,把视图同查询的其它部分合并产生了更好的性能优势。例如,如下查询所用的资源将有非常大的区别,取决于视图是否合并:
select *
from orders o,
(select sales_rep_id
from orders
) o_view
where o.sales_rep_id = o_view.sales_rep_id(+)
and o.order_total > 100000;
Listing 2-4 shows the execution plans for this query when view merging occurs and when it doesn’t.
Notice the plan operations chosen and the A-Rows count (actual rows retrieved in that step of the plan)
in each step.
列表2-4展示这个查询当发生视图合并和没有时的执行计划。注意每一步中计划所选的操作(步骤)和A-Rows计数值(计划中的那一步检索的实际行数)
Listing 2-4. View Merging Plan Comparison
-- View merging occurs
--------------------------------------------------------------------------
| Id | Operation | Name | Starts | E-Rows | A-Rows |
--------------------------------------------------------------------------
| 1 | NESTED LOOPS OUTER | | 1 | 413 | 31 |
|* 2 | TABLE ACCESS FULL | ORDERS | 1 | 70 | 7 |
|* 3 | INDEX RANGE SCAN | ORD_SALES_REP_IX | 7 | 6 | 26 |
--------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - filter("O"."ORDER_TOTAL">100000)
3 - access("O"."SALES_REP_ID"="SALES_REP_ID")
filter("SALES_REP_ID" IS NOT NULL)
-- View merging does not occur
-----------------------------------------------------------------
| Id | Operation | Name | Starts | E-Rows | A-Rows |
-----------------------------------------------------------------
|* 1 | HASH JOIN OUTER | | 1 | 413 | 31 |
|* 2 | TABLE ACCESS FULL | ORDERS | 1 | 70 | 7 |
| 3 | VIEW | | 1 | 105 | 104 |
| 4 | TABLE ACCESS FULL | ORDERS | 1 | 105 | 104 |
-----------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - access("O"."SALES_REP_ID"="O_VIEW"."SALES_REP_ID")
2 - filter("O"."ORDER_TOTAL">100000)
Did you notice how in the second, non-merged plan, the view is handled separately? The plan even
indicates the view was kept “as is” by showing the VIEW keyword in line 3 of the plan. By treating the
view separately, a full scan of the orders table occurs before it is joined with the outer orders table. But,
in the merged version, the plan operations are merged into a single plan instead of keeping the in-line
view separate. This results in a more efficient index access operation being chosen and requires fewer
rows to be processed (26 vs 104). This example uses small tables, so imagine how much work would
occur if you had really large tables involved in the query. The transformation to merge the view makes
the plan perform more optimally overall.
你注意到在第二个,没有合并的计划中,视图是单独处理的么?计划中甚至指出视图被保持,“当做是”,在计划的第三行显示VIEW关键字。由于独立的处理视图,在它连接到外面的order表之前要发生一次对(内部)order表的全表扫描。但是,对于合并的版本,计划操作被合并成一个计划而不是让内联视图保
持独立。这将导致选择更加有效的索引访问操作且需要处理的行更少(26 vs
104)。例子使用的是小表,但可以设想如果你真在查询中涉及有大表将产生多少工作。合并视图的变换使得整体上计划运行更加优化。
The misconception that an in-line or normal view will be considered first and separately from the
rest of the query often comes from our education about execution order in mathematics. Let’s consider
the following examples:
对内联视图或者普通视图首先被考虑且独立于查询的其它部分的误解通常来自于我们在数学计算顺序的教育经历。让我们考虑下面的例子:
6 + 4 / 2 = 8
(6 + 4) / 2 = 5
The parenthesis in the second example cause the addition to happen first, whereas in the first
example the division would happen first based on the rules of precedence order. We are trained to know
that when we use parenthesis, that action will happen first. But the SQL language doesn’t follow the
same rules that mathematical expressions do.
Using parenthesis to set a query block apart from another
does not in any way guarantee that block will be executed separately or first.
If you have written your
statement to include an in-line view because you intend for that view to be considered separately, you
may need to add the
NO_MERGE
hint to that query block to prevent it from being rewritten.
As a matter of fact, using the NO_MERGE hint is how I was able to produce the non-merged plan in Listing 2-4. With this hint, I was able to tell the query transformer that I wanted the o_view query block to be considered
independently from the outer query block. The query using the hint actually looked like this:
在第二个例子中的括号使得加法首先运算,而在第一例子中除法将先于加法,基于计算的优先顺序。我们(被教育而)知道当我们使用括号,其中的动作将首先发生。但是SQL语言不遵循数学表达式那套规则。
使用括号来设置查询块而与其他部分分隔开来的做法不能保证块独立或首先运行。
如果你所写的语句中包含内联视图,因为你意图视图被分别考虑,你可能需要加NO_MERGE在查询块中防止它被重写。
事实上,我就是使用NO_MERGE提示生成列表2-4中非合并计划的。使用这个提示,我能告诉查询变换我想让o_view查询块独立考虑于外部查询。使用提示的查询实际上看起来像这样:
select *
from orders o,
(select /*+ NO_MERGE */ sales_rep_id
from orders
) o_view
where o.sales_rep_id = o_view.sales_rep_id(+)
and o.order_total > 100000;
There are some conditions that, if present, will also prevent view merging from occurring. If a query
block contains analytic or aggregate functions, set operations (such as UNION, INTERSECT, MINUS), an ORDER BY clause, or uses ROWNUM, view merging will be prohibited or limited.
Even if some of these conditions are present, you can force view merging to take place by using the MERGE
hint.
If you force view merging to occur by using the hint, you must make sure that the query result set is still correct after the merge.
If view merging was not going to occur, it was likely due to the fact that the merge might cause the query result to be different. By using the hint, you are indicating the merge will not affect the answer. Listing 2-5 shows a statement with an aggregate function that does not view merge and how the use of a MERGE hint can force view merging to occur.
有些条件,如果存在,也将阻止视图合并的发生。如果一查询块包含分析或聚合函数,集合操作(如UNION, INTERSECT,
MINUS),ORDER
BY子句,或使用ROWNUM,视图合并将被禁止或限制。即使这些条件中的一些存在,你能使用MERGE
提示强制视图合并发生。
如果你使用提示强制视图合并发生,你必须确保在合并后查询结果集依然正确。
如果视图合并没有发生,很可能由于事实上合并可能导致不同的查询结果。通过使用提示,你指明合并将不会影响
结果。列表2-5展示了一带有聚合函数的语句没有视图合并,而如何使用MERGE提示强制视图合并发生。
Listing 2-5. The MERGE Hint
SQL> SELECT e1.last_name, e1.salary, v.avg_salary
2 FROM employees e1,
3 (SELECT department_id, avg(salary) avg_salary
4 FROM employees e2
5 GROUP BY department_id) v
6 WHERE e1.department_id = v.department_id AND e1.salary > v.avg_salary;
...
38 rows selected.
Execution Plan
----------------------------------------------------------
Plan hash value: 2695105989
----------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU) | Time |
----------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 17 | 697 | 8 (25) | 00:00:01 |
|* 1 | HASH JOIN | | 17 | 697 | 8 (25) | 00:00:01 |
| 2 | VIEW | | 11 | 286 | 4 (25) | 00:00:01 |
| 3 | HASH GROUP BY | | 11 | 77 | 4 (25) | 00:00:01 |
| 4 | TABLE ACCESS FULL | EMPLOYEES | 107 | 749 | 3 (0) | 00:00:01 |
| 5 | TABLE ACCESS FULL | EMPLOYEES | 107 | 1605 | 3 (0) | 00:00:01 |
----------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - access("E1"."DEPARTMENT_ID"="V"."DEPARTMENT_ID")
filter("E1"."SALARY">"V"."AVG_SALARY")
SQL> SELECT /*+ MERGE(v) */ e1.last_name, e1.salary, v.avg_salary
2 FROM employees e1,
3 (SELECT department_id, avg(salary) avg_salary
4 FROM employees e2
5 GROUP BY department_id) v
6 WHERE e1.department_id = v.department_id AND e1.salary > v.avg_salary;
...
38 rows selected.
Execution Plan
----------------------------------------------------------
Plan hash value: 3553954154
----------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU) | Time |
----------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 165 | 5610 | 8 (25) | 00:00:01 |
|*
1 | FILTER | | | | | |
| 2 | HASH GROUP BY | | 165 | 5610 | 8 (25) | 00:00:01 |
|* 3 | HASH JOIN | | 3296 | 109K | 7 (15) | 00:00:01 |
| 4 | TABLE ACCESS FULL | EMPLOYEES | 107 | 2889 | 3 (0) | 00:00:01 |
| 5 | TABLE ACCESS FULL | EMPLOYEES | 107 | 749 | 3 (0) | 00:00:01 |
----------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter("E1"."SALARY">SUM("SALARY")/COUNT("SALARY"))
3 - access("E1"."DEPARTMENT_ID"="DEPARTMENT_ID")
View merging behavior is controlled by the hidden parameter _complex_view_merging that defaults
to TRUE in version 9 and above. Starting in version 10, transformed queries are reviewed by the optimizer
and the costs of both the merged and non-merged plans are evaluated. The optimizer will then choose
the plan that is the least costly.
试图合并行为被隐式参数_complex_view_merging所控制,默认值在版本9之前是TRUE。至10起,查询变换由优化器检查,合并和非合并的成本都会被评估。优化器将选择最少成本的计划。
发表评论
-
《Pro Oracle SQL》Chapter2--2.13 SQL Execution – Putting It All Together
2012-02-10 05:26 1163SQL Execution – Putting It All ... -
《Pro Oracle SQL》CHAPTER2--2.12Executing the Plan and Fetching Rows
2012-02-09 09:41 1184Executing the Plan and Fetching ... -
《Pro Oracle SQL》CHAPTER2--2.11 Determining the Execution Plan
2012-02-04 20:09 1066Determining the Execution Plan ... -
《Pro Oracle SQL》CHAPTER2--2.10 Query Rewrite with Materialized Views
2012-01-27 13:27 1007Query Rewrite with Materialized ... -
《Pro Oracle SQL》CHAPTER2--2.9 Predicate Pushing
2012-01-25 20:51 1339Predicate Pushing 谓词推进 ... -
《Pro Oracle SQL》CHAPTER2--2.8 Subquery Unnesting
2012-01-23 20:51 1466Subquery Unnesting 子查询 ... -
《Pro Oracle SQL》CHAPTER2--2.6Query Transformation
2012-01-18 15:17 759Query Transformation 查询变换 ... -
《Pro Oracle SQL》Charpter2 --2.5 SGA – The Buffer Cache
2012-01-15 16:10 1067SGA – The Buffer Cache SGA-缓 ... -
《Pro Oracle SQL》Chapter 2--2.4 Identical Statements
2012-01-14 14:42 9632.4 Identical Statements 同 ... -
《Pro Oracle SQL》CHAPTER2--2.3 The Library Cache
2012-01-10 22:00 802The Library Cache 库缓存 ... -
《Pro Oracle SQL》Chapter2-2.2 SGA – The Shared Pool
2012-01-08 16:16 9252.2 SGA – The Shared Pool ... -
《Pro Oracle SQL》 Chapter2--2.1 Oracle Architecture Basics
2012-01-03 11:13 1297Chapter 2 SQL Execution ...
相关推荐
在这个特定的“IntervalTree-with-merging-interval”项目中,我们关注的是一个能够合并重叠区间的区间树实现,这在很多实际应用中非常有用,比如日程安排、资源分配或者基因序列分析等。 区间树通常基于二叉搜索树...
根据文档中的内容,《etap-merging-library-addition-75.pdf》主要涉及三类新增设备:高压断路器(High Voltage Circuit Breaker, HVCB)、继电器(Relays)以及低压断路器(Low Voltage Circuit Breaker, LVCB)。...
"merging--data"这个项目显然关注的是如何使用JavaScript来合并不同的数据源。JavaScript,作为一种广泛应用于前端开发和后端Node.js环境的语言,也具备处理数据的能力。下面我们将详细探讨JavaScript在数据合并中的...
在TypeScript中,声明合并是一种核心特性,它允许开发者在同一作用域内合并多个相同名称的声明,从而构建更复杂的类型系统。这一特性尤其在处理现有的JavaScript库和模块时显得尤为重要,因为它能帮助编译器理解那些...
根据提供的信息,“r43ples-merging-client”似乎是一个用于合并 R43ples 客户端的工具或库,可能是为了整合多个 R43ples 客户端实例的功能或数据。这里我们将围绕 Java 开发和客户端合并两个关键点来深入探讨相关的...
2. 方法论 本文的方法基于两个关键步骤:合并与分裂。在每个时间步开始时,检测并合并碰撞的粒子,这有助于消除潜在的穿透问题。接着,在时间步结束时,根据需要将这些合并的粒子重新分开,以便它们在下一个时间步...
翻译了下面文献:《Single-Scale Fusion An Effective Approach to Merging Images》,汉语名《单尺度融合——一种融合图像的有效方法》。压缩包里有英语原文和我的翻译。
在MATLAB中开发3D点云处理项目时,"Merging3dpointclouds透视增强"涉及的关键技术点包括3D点云数据处理、颜色传播、透视校正以及视觉增强。下面将对这些主题进行详细阐述。 首先,3D点云是一种在三维空间中表示物体...
涵盖利用光学元件,视频投影仪,全息图,射频标签和跟踪技术以及交互式渲染算法和校准技术的空间增强现实方法。
The joint development of the upcoming High Efficiency Video Coding (HEVC) standard by ITU-T Video Coding Experts Group and ISO/IEC Moving Picture Experts Group marks a new step in video compression ...
区域生长的matlab源码 region grow
- **View Merging**:将视图定义合并到查询中,避免额外的查询执行。 - **Predicate Pushing**:将过滤条件尽可能下推到基表中,减少返回的数据量。 - **Materialized Views**:预先计算并存储复杂查询的结果,...
final_merging_code.m 中使用的 matlab 函数来执行二维卷积。 实现此功能仅用于理解图像 2d 卷积。 此代码只能使用 3X3 矩阵执行 2d 卷积。(此代码可能效率不高,因此为了更快的实现,在 Matlab 中用 conv2() 函数...
Oracle 8i 开始有四种转换技术:视图合并(View Merging)、谓词推进(Predicate Pushing)、非嵌套子查询(Subquery Unnesting)和物化视图的查询重写(Query Rewrite with Materialized Views)。 CBO 优化器可以...
Certification Authorities Software Team (CAST) Position Paper CAST-15 Merging High-Level and Low-Level Requirements Completed February 2003
在GitHub上进行协同开发时,Pull Request(PR)是一种常用的工作流程,用于将代码更改从一个分支合并到另一个分支,通常是将开发分支的更改合并到主分支。然而,在代码未完成或审查之前,我们可能不希望让其他开发者...
在本项目中,“Merging-images-project”是一个使用Java编写的软件工具,它的主要功能是将多张图片合并成一张单一的图像。这个工具对于需要整合多个视觉元素或者创建复合图像的用户来说非常实用,比如设计师、摄影师...
彩色图像区域合并算法,高斯分布,有注释,后来用于极化SAR伪彩色图区域分割,引入Wishart分布
文章中提到的优化器参数包括Optimizer_mode, optimizer_secure_view_merging, optimizer_use_invisible_indexes等,这些参数可以影响优化器的行为和决策。 在进行优化时,优化器会使用数据库收集的统计信息,如块数...
神经元合并:补偿修剪的神经元 在第34届神经信息处理系统会议(NeurIPS 2020)上接受的神经元合并的Pytorch实现:补偿修剪的神经元。 要求 要安装要求: conda env create -f ./environment.yml ...