简体   繁体   English

在Oracle 12c中查看外部联接的性能问题

[英]Performance issues with outer joins to view in Oracle 12c

Two of my clients have recently upgraded to Oracle 12c 12.1.0.2 . 我的两个客户最近升级到Oracle 12c 12.1.0.2 Since the upgrade I am experiencing significant performance degradation on queries using views with outer joins. 自升级以来,我在使用具有外连接的视图的查询中遇到显着的性能下降。 Below is an example of a simple query that runs in seconds on the old Oracle 11g 11.2.0.2 database but takes several minutes on the new 12c database. 下面是一个简单查询的示例,该查询在旧的Oracle 11g 11.2.0.2数据库上以秒为单位运行,但在新的12c数据库上需要几分钟。 Even more perplexing, this query runs reasonably fast (but not as fast) on one of the 12c databases, but not at all on the other. 更令人困惑的是,这个查询在12c数据库中的一个上运行得相当快(但不是那么快),但在另一个数据库上运行得不是很快。 The performance is so bad on the one 12c database that the reporting I've developed is unusable. 在一个12c数据库上,性能非常糟糕,我开发的报告无法使用。

I've compared indexes and system parameters between the 11g and two 12c databases, and have not found any significant differences. 我已经比较了11g和两个12c数据库之间的索引和系统参数,但没有发现任何显着差异。 There is a difference between the Execution Plans , however. 但是, Execution Plans之间存在差异。 On 11g the outer join is represented as VIEW PUSHED PREDICATE but on 12c it is represented as a HASH JOIN without the PUSHED PREDICATE . 11g ,外连接表示为VIEW PUSHED PREDICATE但在12c它表示为没有PUSHED PREDICATEHASH JOIN

When I add the hint /*+ NO_MERGE(pt) PUSH_PRED(pt) */ to the query on the 12c database, then the performance is within seconds. 当我将提示/*+ NO_MERGE(pt) PUSH_PRED(pt) */12c数据库上的查询时,性能在几秒钟内。

Adding a hint to the SQL is not an option within our Crystal Reports (at least I don't believe so and also there are several reports), so I am hoping we can figure out why performance is acceptable on one 12c database but not on the other. 在我们的Crystal Reports添加提示不是一个选项(至少我不相信,也有几个报告),所以我希望我们可以弄清楚为什么性能在一个12c数据库上是可接受的但不是另一个。

My team and I are stumped at what to try next, and particularly why the response would be so different between the two 12c databases. 我和我的团队难以接受下一步的尝试,特别是为什么两个12c数据库之间的响应会如此不同。 We have researched several articles on performance degradation in 12c , but nothing appears particularly applicable to this specific issue. 我们已经在12c研究了几篇关于性能下降的文章,但没有什么特别适用于这个特定问题。 As an added note, queries using tables instead of views are returning results within an acceptable timeframe. 作为补充说明,使用表而不是视图的查询将在可接受的时间范围内返回结果。 Any insights or suggestions would be greatly appreciated. 任何见解或建议将不胜感激。

11g数据库

12c数据库

Query: 查询:

select pi.*
, pt.*
from policyissuance_oasis pi
, policytransaction_oasis pt
where 
pi.newTranKeyJoin = pt.polTranKeyJoin(+)
and pi.policyNumber = '1-H000133'
and pi.DateChars='08/10/2017 09:24:51'    -- 2016 data
--and pi.DateChars = '09/26/2016 14:29:37'  --2013 data
order by pi.followup_time

as krokodilko says, perform these : 正如krokodilko所说,执行以下操作:

explain plan for 
select pi.*
, pt.*
from policyissuance_oasis pi
, policytransaction_oasis pt
where 
pi.newTranKeyJoin = pt.polTranKeyJoin(+)
and pi.policyNumber = '1-H000133'
and pi.DateChars='08/10/2017 09:24:51'    -- 2016 data
--and pi.DateChars = '09/26/2016 14:29:37'  --2013 data
order by pi.followup_time;
select * from table(dbms_xplan.display());

and then, you probably see this at the bottom of the plan : 然后,你可能会在计划的底部看到这个:

Note
-----
   - dynamic statistics used: dynamic sampling (level=2)

there, 那里,

dynamic sampling 动态采样

concept should be the center of concern for performance problems(level=2 is the default value, ranges between 0-11 ). 概念应该是性能问题的关注中心(level = 2是默认值,范围在0-11之间)。

In fact, Dynamic sampling (DS) was introduced to improve the optimizer's ability to generate good execution plans. 实际上,引入了动态采样(DS)来提高优化器生成良好执行计划的能力。 This feature was enhanced and renamed Dynamic Statistics in Oracle Database 12c . 此功能已得到增强,并Dynamic Statistics in Oracle Database 12c重命名为Dynamic Statistics in Oracle Database 12c The most common misconception is that DS can be used as a substitute for optimizer statistics, whereas the goal of DS is to augment optimizer statistics ; 最常见的误解是DS可以用作优化器统计数据的替代,而DS的目标是增加optimizer statistics ; it is used when regular statistics are not sufficient to get good quality cardinality estimates. regular statistics不足以获得高质量的基数估计值时使用它。

For serial SQL statements the dynamic sampling level is controlled by the 对于串行SQL语句, dynamic sampling level

optimizer_dynamic_sampling optimizer_dynamic_sampling

parameter but note that from Oracle Database 12c Release 1 the existence of SQL plan directives can also initiate dynamic statistics gathering when a query is compiled. 但请注意,从Oracle Database 12c Release 1开始, SQL plan directives的存在也可以在编译查询时启动dynamic statistics收集。 This is a feature of adaptive statistics and is controlled by the database parameter 这是自适应统计的一项功能,由数据库参数控制

optimizer_adaptive_features (OAF) optimizer_adaptive_features(OAF)

in Oracle Database 12c Release 1 and Oracle Database 12c Release 1Oracle Database 12c Release 1

optimizer_adaptive_statistics (OAS) optimizer_adaptive_statistics(OAS)

in Oracle Database 12c Release 2 . Oracle Database 12c Release 2

In other words, from Oracle Database 12c Release 1 (we also use db12.1.0.2 at office) onwards, DS will be used if certain adaptive features are enabled by setting the relevant parameter to TRUE . 换句话说,从Oracle Database 12c Release 1 (我们也在办公室使用db12.1.0.2)开始,如果通过将相关参数设置为TRUE来启用某些自适应功能,则将使用DS

Serial statements are typically short running and any DS overhead at compile time can have a large impact on overall system performance (if statements are frequently hard parsed). 串行语句通常运行时很短,编译时的任何DS开销都会对整体系统性能产生很大影响(如果语句经常被硬分析)。 For systems that match this profile, setting OAF=FALSE is recommended( alter session set optimizer_adaptive_features=FALSE notice that 对于与此配置文件匹配的系统,建议设置OAF=FALSEalter session set optimizer_adaptive_features=FALSE注意到

you shouldn't alter system but session 你不应该改变系统而是会话

). )。

For Oracle Database 12c Release 2 onwards , using the default OAS=FALSE is recommended. 对于Oracle Database 12c Release 2 onwards ,建议使用默认的OAS=FALSE

Parallel statements are generally more resource intensive, so it's often worth investing in additional overhead at compile time to potentially find a better SQL execution plan . Parallel statements通常需要更多的资源,因此在编译时投入额外的开销通常值得找到更好的SQL execution plan

For serial type SQL statements , you may try to manual set the value for optimizer_dynamic_sampling (assuming that there were no relevant SQL plan directives). 对于serial type SQL statements ,您可以尝试手动设置optimizer_dynamic_sampling的值(假设没有相关的SQL计划指令)。 If we were to issue a similar style of query against a larger table that had the parallel attribute set we can see the dynamic sampling kicking in. 如果我们对具有并行属性集的较大表发出类似的查询样式,我们可以看到动态采样。

When should you use dynamic sampling ? 什么时候应该使用dynamic sampling DS is typically recommended when you know you are getting a bad execution plan due to complex predicates. 当您知道由于复杂谓词而导致执行计划错误时,通常会建议使用DS But shouldn't be system-wide as i mentioned before. 但不应该像我之前提到的那样在全系统范围内。

When is it not a good idea to use dynamic sampling ? 何时使用dynamic sampling不是一个好主意? If the queries compile times need to be as fast as possible, for example, unrepeated OLTP queries where you can't amortize the additional cost of compilation over many executions. 如果查询编译时间需要尽可能快,例如,不重复的OLTP查询,您无法通过多次执行来分摊额外的编译成本。

As the last word, for your case, it could be beneficient to set optimizer_adaptive_features parameter to FALSE for individual SQL statements and see the gained results. 最后一句话,对于您的情况,将各个SQL语句的optimizer_adaptive_features参数设置为FALSE并查看获得的结果可能是有益的。

We discovered the cause of the performance issue. 我们发现了性能问题的原因。 The following 2 system parameters were changed at the system level by the DBAs for the main application that uses our client's Oracle server: 对于使用客户端Oracle服务器的主应用程序,DBA在系统级别更改了以下2个系统参数:

_optimizer_cost_based_transformation = OFF 
_optimizer_reduce_groupby_key = FALSE

When we changed them at the session level to the following, the query above that joins the 2 views returns results in less than 2 seconds: 当我们在会话级别将它们更改为以下内容时,连接2个视图的上述查询将在不到2秒的时间内返回结果:

alter session set "_optimizer_cost_based_transformation"=LINEAR;
alter session set "_optimizer_reduce_groupby_key" = TRUE;
COMMIT;

Changing this parameter did not have an impact on performance: 更改此参数对性能没有影响:

alter session set optimizer_adaptive_features=FALSE;
COMMIT;

We also found that changing the following parameter improved performance even more for our more complex views: 我们还发现,对于更复杂的视图,更改以下参数可以进一步提高性能:

alter session set optimizer_features_enable="11.2.0.3";
COMMIT;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM