CONCATENATION 引发的性能问题
背景是在一台11gR2的机器上,开发反映一个批处理比以前慢了3倍。经过仔细查看该SQL的执行计划,发现由于SQL中使用了or,导致CBO走出了一个非常糟糕的CONCATENATION路径。
no_expand提示的说明是 The NO_EXPAND hint prevents the cost-based optimizer from considering OR-expansion for queries having OR conditions or IN-lists in the WHERE clause. Usually, the optimizer considers using OR expansion and uses this method if it decides that the cost is lower than not using it. use_concat提示的说明是 The USE_CONCAT hint forces combined OR conditions in the WHERE clause of a query to be transformed into a compound query using the UNION ALL set operator. Generally, this transformation occurs only if the cost of the query using the concatenations is cheaper than the cost without them. 为了重现这个问题,必须使用/*+ use_concat */来模拟。 explain plan for SELECT /*+ use_concat */
20130620,
B.mgr_code ,
B.mgr_name ,
B.cur_name ,
'3.4.2' ,
nvl(sum(ADJUST_AMT_AF),0) as acct_bal ,
nvl(sum(D_CMP_BAL),0) ,
nvl(sum(M_CMP_BAL),0) ,
nvl(sum(Y_CMP_BAL),0) ,
nvl(sum(Y_avg_af),0) as Y_avg_bal,
B.cur_code,
B.unit1_code,
B.unit2_code,
B.unit3_code,
B.dept1_code,
A.idx_name
FROM S_PM_IDX_CODE A,T_PM_ACCT_DTL_AF B
where B.ACCT_FLAG in('OPEN','LOAN')
AND A.ROWID='AABK8vAAyAAGg/2AAs'
AND SUBSTR(B.FLAG,1,1) IN ('3')
AND SUBSTR(B.FLAG,2,1) IN ('2')
AND SUBSTR(B.FLAG,3,1) IN ('2')
AND 1=1
AND 1=1
AND 1=1
AND 1=1
AND 1=1
AND 1=1
AND 1=1
and ((A.term_flag is null)
or (A.term_flag is not null and A.begin_term<B.term
and A.end_term >= B.term and B.term_flag = A.term_flag))
AND B.data_date = 20130620
group by B.mgr_code, B.mgr_name,
B.cur_code, B.cur_name,
B.unit1_code,B.unit2_code,
B.unit3_code,
B.dept1_code,
A.IDX_NAME; Plan hash value: 542663423 ------------------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | Pstart| Pstop |
------------------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 240 | 47236 (1)| 00:09:27 | | |
| 1 | HASH GROUP BY | | 1 | 240 | | | | |
| 2 | CONCATENATION | | | | | | | |
| 3 | NESTED LOOPS | | 1 | 240 | 23609 (1)| 00:04:44 | | |
|* 4 | TABLE ACCESS BY USER ROWID| S_PM_IDX_CODE | 1 | 97 | 1 (0)| 00:00:01 | | |
| 5 | PARTITION LIST SINGLE | | 1 | 143 | 23608 (1)| 00:04:44 | KEY | KEY |
|* 6 | TABLE ACCESS FULL | T_PM_ACCT_DTL_AF | 1 | 143 | 23608 (1)| 00:04:44 | 549 | 549 |
| 7 | NESTED LOOPS | | 1 | 240 | 23625 (1)| 00:04:44 | | |
|* 8 | TABLE ACCESS BY USER ROWID| S_PM_IDX_CODE | 1 | 97 | 1 (0)| 00:00:01 | | |
| 9 | PARTITION LIST SINGLE | | 1 | 143 | 23624 (1)| 00:04:44 | KEY | KEY |
|* 10 | TABLE ACCESS FULL | T_PM_ACCT_DTL_AF | 1 | 143 | 23624 (1)| 00:04:44 | 549 | 549 |
------------------------------------------------------------------------------------------------------------------ Predicate Information (identified by operation id):
--------------------------------------------------- 4 - filter("A"."TERM_FLAG" IS NOT NULL)
6 - filter("A"."BEGIN_TERM"<"B"."TERM" AND "A"."END_TERM">="B"."TERM" AND
"B"."TERM_FLAG"="A"."TERM_FLAG" AND ("B"."ACCT_FLAG"='LOAN' OR "B"."ACCT_FLAG"='OPEN') AND
SUBSTR("B"."FLAG",2,1)='2' AND SUBSTR("B"."FLAG",3,1)='2' AND SUBSTR("B"."FLAG",1,1)='3' AND
"B"."DATA_DATE"=20130620)
8 - filter("A"."TERM_FLAG" IS NULL)
10 - filter(("B"."ACCT_FLAG"='LOAN' OR "B"."ACCT_FLAG"='OPEN') AND SUBSTR("B"."FLAG",2,1)='2' AND
SUBSTR("B"."FLAG",3,1)='2' AND SUBSTR("B"."FLAG",1,1)='3' AND "B"."DATA_DATE"=20130620 AND
(LNNVL("B"."TERM_FLAG"="A"."TERM_FLAG") OR LNNVL("A"."BEGIN_TERM"<"B"."TERM") OR
LNNVL("A"."END_TERM">="B"."TERM") OR LNNVL("A"."TERM_FLAG" IS NOT NULL))) Note
-----
- dynamic sampling used for this statement (level=2) explain plan for
SELECT
20130620,
B.mgr_code ,
B.mgr_name ,
B.cur_name ,
'3.4.2' ,
nvl(sum(ADJUST_AMT_AF),0) as acct_bal ,
nvl(sum(D_CMP_BAL),0) ,
nvl(sum(M_CMP_BAL),0) ,
nvl(sum(Y_CMP_BAL),0) ,
nvl(sum(Y_avg_af),0) as Y_avg_bal,
B.cur_code,
B.unit1_code,
B.unit2_code,
B.unit3_code,
B.dept1_code,
A.idx_name
FROM S_PM_IDX_CODE A,T_PM_ACCT_DTL_AF B
where B.ACCT_FLAG in('OPEN','LOAN')
AND A.ROWID='AABK8vAAyAAGg/2AAs'
AND SUBSTR(B.FLAG,1,1) IN ('3')
AND SUBSTR(B.FLAG,2,1) IN ('2')
AND SUBSTR(B.FLAG,3,1) IN ('2')
AND 1=1
AND 1=1
AND 1=1
AND 1=1
AND 1=1
AND 1=1
AND 1=1
and ((A.term_flag is null)
or (A.term_flag is not null and A.begin_term<B.term
and A.end_term >= B.term and B.term_flag = A.term_flag))
AND B.data_date = 20130620
group by B.mgr_code, B.mgr_name,
B.cur_code, B.cur_name,
B.unit1_code,B.unit2_code,
B.unit3_code,
B.dept1_code,
A.IDX_NAME;
select * from table(dbms_xplan.display());
Plan hash value: 2396922436 ------------------------------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | Pstart| Pstop |
------------------------------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 240 | 8058 (1)| 00:01:37 | | |
| 1 | HASH GROUP BY | | 1 | 240 | 8058 (1)| 00:01:37 | | |
| 2 | NESTED LOOPS | | 1 | 240 | 8057 (1)| 00:01:37 | | |
| 3 | TABLE ACCESS BY USER ROWID | S_PM_IDX_CODE | 1 | 97 | 1 (0)| 00:00:01 | | |
| 4 | PARTITION LIST SINGLE | | 1 | 143 | 8056 (1)| 00:01:37 | KEY | KEY |
|* 5 | TABLE ACCESS BY LOCAL INDEX ROWID| T_PM_ACCT_DTL_AF | 1 | 143 | 8056 (1)| 00:01:37 | 549 | 549 |
|* 6 | INDEX RANGE SCAN | T_PM_ACCT_DTL_AF_IDX1 | 35022 | | 136 (1)| 00:00:02 | 549 | 549 |
------------------------------------------------------------------------------------------------------------------------------ Predicate Information (identified by operation id):
--------------------------------------------------- 5 - filter(("B"."ACCT_FLAG"='LOAN' OR "B"."ACCT_FLAG"='OPEN') AND SUBSTR("B"."FLAG",2,1)='2' AND
SUBSTR("B"."FLAG",3,1)='2' AND ("A"."TERM_FLAG" IS NULL OR "B"."TERM_FLAG"="A"."TERM_FLAG" AND
"A"."BEGIN_TERM"<"B"."TERM" AND "A"."END_TERM">="B"."TERM" AND "A"."TERM_FLAG" IS NOT NULL))
6 - access(SUBSTR("FLAG",1,1)='3') Note
-----
- dynamic sampling used for this statement (level=2)
CONCATENATION 引发的性能问题的更多相关文章
- Mysql中where条件一个单引号引发的性能损耗
日常写SQL中可能会有一些小细节忽略了导致整个sql的性能下降了好几倍甚至几十倍,几百倍.以下这个示例就是mysql语句中的一个单引号('')引发的性能耗损,我相信很多朋友都遇到过,甚至还在这样写. ...
- 调用.NET Serviced Component引发的性能问题及其解决
在企业用户环境里,.NET Serviced Component使用广泛.它比较好的把传统COM+封装和.NET应用逻辑衔接了起来,在服务器端应用起到重要作用..NET Serviced Compon ...
- try catch引发的性能优化深度思考
关键代码拆解成如下图所示(无关部分已省略): 起初我认为可能是这个 getRowDataItemNumberFormat 函数里面某些方法执行太慢,从 formatData.replace 到 une ...
- 记一个由MemCached引发的性能问题
最近有个项目用loadrunner做了压力测试,发现并发量还不到200服务器就支撑不住了.boss那边紧急开会,说此项目最近3个月内将有100家中大型公司用于校园招聘工作,如果这个问题不解决公司有可能 ...
- linux 内核中一个全局变量引发的性能问题
为了调试一个功能,在一个内核模块中,增加了一个全局变量,用来统计自有skb池的申请情况. 因为是临时增加,所以没有考虑性能,一开始只是一个fail的统计,数量不多,也不太考虑是否有计数丢失的情况,毕竟 ...
- 由一次自建库迁移到阿里云RDS引发的性能问题。
刚入职一互联网公司,项目正好处于计划上线的时间,由于公司前不久已经购买了rds服务,领导决定尝试一番! 当然,新事物.云事物还是要谨慎的.安排我先把测试环境数据库迁移上去,这里吐槽一下,往rds迁移一 ...
- (转)Linux NUMA引发的性能问题
最近某客户的核心业务系统又出了翻译缓慢的情况.该问题在6月份也出现过,当时进行了一次调整. 我们首先来看下故障时间段的awr报告: 单纯的从TOP 5 event,基本上是看不出任何东西的,可能有人会 ...
- 系统级性能分析工具perf的介绍与使用
测试环境:Ubuntu16.04(在VMWare虚拟机使用perf top存在无法显示问题) Kernel:3.13.0-32 系统级性能优化通常包括两个阶段:性能剖析(performance pro ...
- 视图合并、hash join连接列数据分布不均匀引发的惨案
表大小 SQL> select count(*) from agent.TB_AGENT_INFO; COUNT(*) ---------- 1751 SQL> select count( ...
随机推荐
- awk实用技巧
awk '{sum+=$1} END {print "Sum = ", sum}' awk '{sum+=$1} END {print "Average = " ...
- radio的change事件
radio的change事件 <scripttype="text/javascript"> $(document).ready(function(){ $(" ...
- memcached 安装
安装 memcached 需要 三部1,下载 memcached 放到php目录将php_memcached.dll 放到php的ext 目录 2,打开管理员命令,将memcached 拖拉到命令中, ...
- spring security 11种过滤器介绍
1.HttpSessionContextIntegrationFilter 位于过滤器顶端,第一个起作用的过滤器. 用途一,在执行其他过滤器之前,率先判断用户的session中是否已经存在一个Secu ...
- [序列化] SerializeHelper--序列化操作帮助类 (转载)
点击下载 SerializeHelper.zip 这个类是关于加密,解密的操作,文件的一些高级操作1.XML序列化2.Json序列化3.SoapFormatter序列化4.BinaryFormatte ...
- [字符串] AppMessage--字符串返回帮助类 (转载)
点击下载 AppMessage.rar 这个类是关于AppMessage的帮助类,主要是格式化返回字符串的里面会有很多的提供字符的格式以及预设置内容,大家可以直接使用的看下面代码吧 /// <s ...
- BigDecimal类型的详情
一.简介 1.概述 BigDecimal由任意精度的整数非标度值和32位的整数标度(scale)组成.如果为零或正数,则标度是小数点后的位数.如果为负数,则将该数的非标度值乘以10的负scale次幂. ...
- iOS开发内购图文教程
2015年最全的内购图文教程,首先是填各种资料,最后是代码,废话不多说,直接上图 ======================第一部分协议=============== 第一步.png 第二步.jpg ...
- CSS3弹性盒模型flex box快速入门 2016.03.16
@import url(http://i.cnblogs.com/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/c ...
- 169. Majority Element(C++)
169. Majority Element Given an array of size n, find the majority element. The majority element is t ...