Query Transformation 查询变换 (Page 61)
Prior to the development of the execution plan, a step called query transformation occurs.
This step
happens just after a query is checked for syntax and permissions and just before the optimizer computes
cost estimates for the various plan operations it considers when determining the final execution plan. In
other words, transformation and optimization are two different tasks.
在生成执行计划之前,有一步称之为“查询变换”的步骤将发生。
这一步紧接着查询的语法和权限被检查之后,且在优化器计算成本,评估它所考虑的各种计划操作,确定最终执行计划之前执行。换句话说,变换和优化是两个不同的任务。
After your query passes the syntactical and permissions checks, the query enters the transform
phase in a set of query blocks. A query block is defined by the keyword SELECT. For example, select
*
from employees where department_id = 60 has a single query block.
However, select * from employees where department_id in (select
department_id from departments) has two query blocks. Each query block is either nested within another or interrelated to another in some way. The way the query is written determines the relationships between query blocks. It is the query transformer’s main objective to determine if changing the way the query is written will provide a better query plan.
在你的查询通过语法和权限检查之后,查询进入一组查询块集的变换阶段。一查询块被关键字SELECT所定义。例如select *
from employees where department_id = 60有一个单独的查询块。然而,select * from
employees where department_id in (select department_id from departments)
有两个查询块。每个查询块要么嵌入另一个之中或者以某种方式关联到其他块中。书写查询的方式确定了查询块之间的关系。查询变换的主要目的是确定是否改变所写的查询方式将生成更佳的查询计划。
Make sure you caught that last sentence. The query transformer can, and will, rewrite your query.
This is something you may have never realized. What you write may not end up being the exact
statement for which the execution plan is developed.
Many times this is a good thing. The query
transformer knows how the optimizer deals with certain syntax and will do everything it can to render
your SQL in a way that helps the optimizer to come up with the best, most efficient execution plan.
However, the fact that what you write can be changed may mean that a behavior you expected,
particularly the order in which certain parts of the statement occur, doesn’t happen the way you
intended. Therefore, you really need to understand how query transformation works so that you can
make sure to write your SQL properly to get the behaviors you intend.
务必关注上面的语句。查询变换器能够,也会,重写你的查询。可能你从来没有意识到。你所写的(语句)可能最终不是开发执行计划时(所参考)的准确语句。
很多时候这是件好事。查询变换知道优化器如何处理某些语法,然后尽一切可能渲染(加工)你的SQL,帮助优化器生成最佳最有效的执行计划。然而,事实上可能改变你书写的(语句),意味着你所期望的行为,特别是某些部分的语句的执行顺序,不是按照你的意图发生的。因此,你真正需要理解查询变换如何工作的,以至于你能确保以适当的方式书写你的SQL取得期望的行为。
The query transformer may change the way you originally formulated your query as long as the
change does not affect the result set. Any change that might cause the result set to differ from the
original query syntax will not be considered. The change that is most often made is to transform
separate query blocks into straight joins. For example, this statement
select * from employees where department_id in (select department_id from departments)
will likely be transformed into this statement
select e.* from employees e, departments d where e.department_id = d.department_id
The result set doesn’t change, but the execution plan choices for the transformed version would be
better from the optimizer’s point of view.
查询变换可能改变最初你书写查询的方式,只要改变不影响结果集。任何可能导致结果集不同于最初的查询语法的改变将不被考虑。最常用的改变是变换分散的查询块成直接的连接。例如,语句
select * from employees where department_id in (select department_id from departments)
将可能被变换成语句
select e.* from employees e, departments d where e.department_id = d.department_id
结果集没有改变,但是从优化器的观点来看执行计划选择变换版本(的语句)将更好。
Once you learn what to look for, you can usually tell by looking at the execution plan if a
transformation occurs. You can also execute your query using the NO_QUERY_TRANSFORMATION hint and compare the execution plan from this query with the plan from the query without the hint.
If the two
plans are not the same, the differences can be attributed to query transformation.
When using the hint,
all query transformations with the exception of predicate pushing (which I’ll review shortly) will be
prohibited.
一旦你知道了要查找什么,你就能通过查询执行计划知道是否发生了查询变换。你也可以用NO_QUERY_TRANSFORMATION提示执行你的查询然后将执行计划与不带提示的查询的执行计划相比较。如果两个计划不相同,不同点可归咎于查询变换。
当使用了提示,所有除“谓词
推进
”(我等会讲解)
之外的查询变换将被禁止。
There are several basic transformations that can be applied to a given query:
-
View merging
-
Subquery unnesting
-
Predicate pushing
-
Query rewrite with materialized views
有如下几种基本的变换可以应用于给定的查询:
-
视图合并
-
子查询反嵌套
-
谓词推进
-
用物化视图重写查询
分享到:
相关推荐
- **Spark SQL**:Spark的SQL模块,支持使用SQL查询DataFrame,同时兼容Hive的元数据和SQL语法。 - **Spark Streaming**:用于实时流数据处理,通过将数据流划分为微批次进行处理。 - **MLlib**:机器学习库,包含...
RDDs支持两种操作:转换(Transformation)和动作(Action)。转换创建新的RDD,而动作触发计算并可能返回结果到驱动程序或写入外部存储。 2. **Spark组件**: - **Spark Core**:基础执行引擎,负责任务调度、...
1. SQL和DataFrame支持:Spark SQL提供了对结构化数据的处理能力,通过DataFrame API,开发者可以使用类似SQL的语法进行查询。此外,Spark 2.4.1增强了DataFrame/Dataset API的性能和兼容性,支持更多数据源,并且对...
早在十多年前,一些具有前瞻视野的企业以实现“数字化”为目标启动转型实践。但时至今日,可以说尚无家企业能够在真正意义上实现“数字化”。在实现“数字化”的征途上,人们发现,努力愈进,仿佛终点愈远。...
在Oracle数据库中,SQL优化是一个至关重要的环节,它能够显著提高数据库查询的效率和性能。本文将详细介绍Oracle SQL中的“提示”(HINT)技术,这是Oracle SQL优化中使用的一项辅助手段,通过为查询提供额外的优化...
离线安装包,亲测可用
"fab-transformation-master"很可能是项目的主要源代码目录,通常在Git仓库中,"master"分支代表了项目的主线代码。这个目录可能包含了项目的主Java类、布局文件、资源文件等,用户需要将其解压并导入到Android ...
challenges-and-transformation-in-china-food-chain-zh.pdf
在这个“Time-frequency-graph-transformation-toolbox-master - 副本.zip”压缩包中,包含了一个专门用于时频域分析的MATLAB工具箱,为科研和工程应用提供了便利。本文将详细介绍该工具箱及其核心功能。 首先,让...
浮动按钮与菜单切换的效果。...项目地址:https://github.com/konifar/fab-transformation 还有,就是导入我的demo时,别忘了修改SDK的版本:android:targetSdkVersion="",改成你的,我用的是19效果图:
《图像处理中的偏斜变换工具:6Slant-Transformation-Tool.zip预处理解析》 在图像处理领域,预处理是一个至关重要的步骤,它为后续的分析、识别和增强提供了良好的基础。本文将深入探讨一种名为“6Slant-...
"SW-transformation-0.0.1.tar.gz" 是一个针对Python的库,名为“SW-transformation”,版本号为0.0.1。这个库很可能包含了特定的数据转换或处理功能,方便用户进行数据操作。 首先,让我们了解Python库的基本概念...
### 从 SQL Server 迁移大批量数据到 Oracle 在 IT 领域,数据库迁移是一项常见的任务,尤其是在企业级应用中。随着业务的发展和技术的进步,企业可能需要将现有的 SQL Server 数据库迁移到 Oracle 数据库。本文将...
3. **查询分析器(Query Analyzer)**:是用于编写、测试和优化SQL语句的工具。它提供了一个交互式的环境,帮助开发者调试和优化SQL查询,提高查询效率。 4. ** Analysis Services**:提供了在线分析处理(OLAP)和...
- 接下来,使用SQL Server 2005的导入/导出向导(Import and Export Wizard)或Data Transformation Services (DTS)将数据从Oracle导入到SQL Server 2005。 - 在选择源提供程序时,应选择“Microsoft OLE DB ...
### Oracle SQL 优化与调优技术详解:深入理解SQL提示 #### 一、SQL提示的定义及作用 在Oracle数据库的SQL语句中,SQL提示(Hints)是一种用于指导优化器选择特定执行计划的特殊注释语法。这些提示能够帮助数据库...
**2. 案例分析** - **自动驾驶拖拉机**:利用无人机拍摄的4K图像精准施肥和灌溉。 - **增强现实眼镜**:帮助飞机维护工程师实时查看维修手册。 - **智能油泵**:能够自我诊断并避免故障发生。 - **全渠道购物...
吴恩达的《AI Transformation Playbook》是一份深入探讨如何引领企业进入人工智能时代的指南。这份文档基于吴恩达在领导谷歌大脑团队和百度AI集团的经验,这些经验在将谷歌和百度塑造为优秀的人工智能公司过程中发挥...
"gray-scale-transformation-process.zip_scale"这个压缩包文件显然包含了一个关于灰度变换的具体程序,可能是一个实用工具或者示例代码,用于演示如何在图像中应用单映射规则。 灰度变换,顾名思义,是将彩色图像...
本文将详细探讨《BCG-People-and-Organization-Transformation-for-Chinese-Insurers》这份报告中的关键知识点,该报告聚焦于中国保险行业的人员与组织转型,旨在为中国保险公司提供战略指导和实践建议。报告由...