一次性能优化将filter转换
有一条SQL性能有问题,在运行计划中发现filter。遇到它要小心了,类似于nestloop。我曾经的blog对它有研究探索运行计划中filter的原理.用exists极易引起filter.
优化前:
SELECT GGPI.ID,
GGPI.PLAN_STATE,
GGPI.PLAN_TYPE,
GGPI.PLAN_CODE,
GGPI.PLAN_SOURCE_TYPE,
GGPI.PLAN_BEGIN_DATE,
GGPI.PLAN_END_DATE,
GGPI.REAL_BEGIN_DATE,
GGPI.REAL_END_DATE,
GGPI.WORK_MASTER_UNAME,
GGPI.WORK_MASTER_UID,
GGPI.WORK_TEAM_ONAME,
GGPI.WORK_SITE_NAMES,
GGPI.WORK_CONTENT,
GGPI.WORK_TYPE,
GGPI.WORK_MEMBER_UNAMES,
GGPI.DIGGATCH_WORK_UNAME,
GGPI.WORKING
FROM GG_PD_PP_INFO GGPI
WHERE PLAN_STATE IN (50, 60, 70)
AND ((GGPI.PLAN_BEGIN_DATE >= sysdate and GGPI.PLAN_BEGIN_DATE <= sysdate) or
(GGPI.PLAN_END_DATE >= sysdate and GGPI.PLAN_END_DATE <= sysdate) or
(GGPI.PLAN_BEGIN_DATE < sysdate and GGPI.PLAN_END_DATE > sysdate))
AND GGPI.BUREAU_CODE = '0306'
AND (GGPI.WORK_MASTER_UID ='FA3502D1291A4A07A3B9E3E0F9A41904' OR EXISTS
(SELECT 1
FROM GG_PD_PP_WORK_MEMBER PMEM
WHERE PMEM.PROD_PLAN_ID = GGPI.ID
AND PMEM.WORK_MEMBER_UID = 'FA3502D1291A4A07A3B9E3E0F9A41904'
AND PMEM.BUREAU_CODE = '0306'));
Execution Plan
----------------------------------------------------------
Plan hash value: 980323934
-------------------------------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | Pstart| Pstop |
-------------------------------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 9670 | 2039K| 25694 (1)| 00:05:09 | | |
|* 1 | FILTER | | | | | | | |
| 2 | PARTITION LIST SINGLE | | 72882 | 15M| 25694 (1)| 00:05:09 | KEY | KEY |
| 3 | PARTITION RANGE ALL | | 72882 | 15M| 25694 (1)| 00:05:09 | 1 | 14 |
|* 4 | TABLE ACCESS FULL | GG_PD_PP_INFO | 72882 | 15M| 25694 (1)| 00:05:09 | | |
|* 5 | TABLE ACCESS BY GLOBAL INDEX ROWID| GG_PD_PP_WORK_MEMBER | 1 | 49 | 5 (0)| 00:00:01 | 4 | 4 |
|* 6 | INDEX RANGE SCAN | IDX_PP_WORK_MEMBER_PPID | 6 | | 3 (0)| 00:00:01 | | |
-------------------------------------------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter("GGPI"."WORK_MASTER_UID" IS NULL OR EXISTS (SELECT 0 FROM "GG_PD_PP_WORK_MEMBER"
"PMEM" WHERE "PMEM"."PROD_PLAN_ID"=:B1 AND "PMEM"."WORK_MEMBER_UID"='FA3502D1291A4A07A3B9E3E0F9A41904' AND
"PMEM"."BUREAU_CODE"='0306'))
4 - filter(("PLAN_STATE"=50 OR "PLAN_STATE"=60 OR "PLAN_STATE"=70) AND ("GGPI"."PLAN_END_DATE">SYSDATE@! AND
"GGPI"."PLAN_BEGIN_DATE"<SYSDATE@! OR "GGPI"."PLAN_BEGIN_DATE"=SYSDATE@! OR "GGPI"."PLAN_END_DATE"=SYSDATE@!))
5 - filter("PMEM"."WORK_MEMBER_UID"='FA3502D1291A4A07A3B9E3E0F9A41904' AND "PMEM"."BUREAU_CODE"='0306')
6 - access("PMEM"."PROD_PLAN_ID"=:B1)
Statistics
----------------------------------------------------------
1 recursive calls
0 db block gets
103763 consistent gets
0 physical reads
0 redo size
3178 bytes sent via SQL*Net to client
524 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
7 rows processed
优化后:
SELECT GGPI.ID,
GGPI.PLAN_STATE,
GGPI.PLAN_TYPE,
GGPI.PLAN_CODE,
GGPI.PLAN_SOURCE_TYPE,
GGPI.PLAN_BEGIN_DATE,
GGPI.PLAN_END_DATE,
GGPI.REAL_BEGIN_DATE,
GGPI.REAL_END_DATE,
GGPI.WORK_MASTER_UNAME,
GGPI.WORK_MASTER_UID,
GGPI.WORK_TEAM_ONAME,
GGPI.WORK_SITE_NAMES,
GGPI.WORK_CONTENT,
GGPI.WORK_TYPE,
GGPI.WORK_MEMBER_UNAMES,
GGPI.DIGGATCH_WORK_UNAME,
GGPI.WORKING
FROM GG_PD_PP_INFO GGPI
WHERE PLAN_STATE IN (50, 60, 70)
AND ((GGPI.PLAN_BEGIN_DATE >= sysdate and GGPI.PLAN_BEGIN_DATE <= sysdate) or
(GGPI.PLAN_END_DATE >= sysdate and GGPI.PLAN_END_DATE <= sysdate) or
(GGPI.PLAN_BEGIN_DATE < sysdate and GGPI.PLAN_END_DATE > sysdate))
AND GGPI.BUREAU_CODE = '0306'
AND GGPI.WORK_MASTER_UID ='FA3502D1291A4A07A3B9E3E0F9A41904'
union all
SELECT GGPI.ID,
GGPI.PLAN_STATE,
GGPI.PLAN_TYPE,
GGPI.PLAN_CODE,
GGPI.PLAN_SOURCE_TYPE,
GGPI.PLAN_BEGIN_DATE,
GGPI.PLAN_END_DATE,
GGPI.REAL_BEGIN_DATE,
GGPI.REAL_END_DATE,
GGPI.WORK_MASTER_UNAME,
GGPI.WORK_MASTER_UID,
GGPI.WORK_TEAM_ONAME,
GGPI.WORK_SITE_NAMES,
GGPI.WORK_CONTENT,
GGPI.WORK_TYPE,
GGPI.WORK_MEMBER_UNAMES,
GGPI.DIGGATCH_WORK_UNAME,
GGPI.WORKING
FROM GG_PD_PP_INFO GGPI
WHERE PLAN_STATE IN (50, 60, 70)
AND ((GGPI.PLAN_BEGIN_DATE >= sysdate and GGPI.PLAN_BEGIN_DATE <= sysdate) or
(GGPI.PLAN_END_DATE >= sysdate and GGPI.PLAN_END_DATE <= sysdate) or
(GGPI.PLAN_BEGIN_DATE < sysdate and GGPI.PLAN_END_DATE > sysdate))
AND GGPI.BUREAU_CODE = '0306'
AND GGPI.ID in
(SELECT PMEM.PROD_PLAN_ID
FROM GG_PD_PP_WORK_MEMBER PMEM
WHERE PMEM.WORK_MEMBER_UID = 'FA3502D1291A4A07A3B9E3E0F9A41904'
AND PMEM.BUREAU_CODE = '0306');
Execution Plan
----------------------------------------------------------
Plan hash value: 1911592856
-----------------------------------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | Pstart| Pstop |
-----------------------------------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1227 | 316K| 3740 (1)| 00:00:45 | | |
| 1 | UNION-ALL | | | | | | | |
|* 2 | TABLE ACCESS BY GLOBAL INDEX ROWID | GG_PD_PP_INFO | 22 | 4752 | 160 (0)| 00:00:02 | ROWID | ROWID |
|* 3 | INDEX RANGE SCAN | IND_GGPI_WORK_MASTER_UID | 222 | | 5 (0)| 00:00:01 | | |
| 4 | NESTED LOOPS | | 1205 | 311K| 3580 (1)| 00:00:43 | | |
| 5 | NESTED LOOPS | | 1205 | 311K| 3580 (1)| 00:00:43 | | |
| 6 | SORT UNIQUE | | 1205 | 59045 | 2373 (1)| 00:00:29 | | |
|* 7 | TABLE ACCESS BY GLOBAL INDEX ROWID| GG_PD_PP_WORK_MEMBER | 1205 | 59045 | 2373 (1)| 00:00:29 | 4 | 4 |
|* 8 | INDEX RANGE SCAN | IND_GGPW_WORK_MEMBER_UID | 4240 | | 31 (0)| 00:00:01 | | |
|* 9 | INDEX UNIQUE SCAN | PK_GG_PD_PP_INFO | 1 | | 1 (0)| 00:00:01 | | |
|* 10 | TABLE ACCESS BY GLOBAL INDEX ROWID | GG_PD_PP_INFO | 1 | 216 | 2 (0)| 00:00:01 | ROWID | ROWID |
-----------------------------------------------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - filter(("PLAN_STATE"=50 OR "PLAN_STATE"=60 OR "PLAN_STATE"=70) AND ("GGPI"."PLAN_END_DATE">SYSDATE@! AND
"GGPI"."PLAN_BEGIN_DATE"<SYSDATE@! OR "GGPI"."PLAN_BEGIN_DATE"=SYSDATE@! OR "GGPI"."PLAN_END_DATE"=SYSDATE@!) AND
"GGPI"."BUREAU_CODE"='0306')
3 - access("GGPI"."WORK_MASTER_UID"='FA3502D1291A4A07A3B9E3E0F9A41904')
7 - filter("PMEM"."BUREAU_CODE"='0306')
8 - access("PMEM"."WORK_MEMBER_UID"='FA3502D1291A4A07A3B9E3E0F9A41904')
9 - access("GGPI"."ID"="PMEM"."PROD_PLAN_ID")
10 - filter(("GGPI"."PLAN_END_DATE">SYSDATE@! AND "GGPI"."PLAN_BEGIN_DATE"<SYSDATE@! OR
"GGPI"."PLAN_BEGIN_DATE"=SYSDATE@! OR "GGPI"."PLAN_END_DATE"=SYSDATE@!) AND ("PLAN_STATE"=50 OR "PLAN_STATE"=60 OR
"PLAN_STATE"=70) AND "GGPI"."BUREAU_CODE"='0306')
Statistics
----------------------------------------------------------
1 recursive calls
0 db block gets
4321 consistent gets
550 physical reads
0 redo size
3228 bytes sent via SQL*Net to client
524 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
1 sorts (memory)
0 sorts (disk)
7 rows processed
一次性能优化将filter转换的更多相关文章
- 一次性能优化,tps从400+到4k+
项目介绍 路由网关项目watchman ,接收前端http请求转发到后端业务系统,功能安全验证,限流,转发. 使用技术:spring boot+ nreflix zuul,最开始日志使用slf4j+l ...
- MYSQL一次性能优化实战经历[转]
每次经历数据库性能调优,都是对性能优化的再次认识.对自己知识不足的有力验证,只有不断总结.学习才能少走弯路. 一.性能问题描述 应用端反应系统查询缓慢,长时间出不来结果.SQLServer数据库服务器 ...
- 记一次性能优化,限制tcp_timewait数量,快速回收和重用
前言 这篇文章的主题是记录一次Python程序的性能优化,在优化的过程中遇到的问题,以及如何去解决的.为大家提供一个优化的思路,首先要声明的一点是,我的方式不是唯一的,大家在性能优化之路上遇到的问题都 ...
- 排除maven jar冲突 maven tomcat插件启动报错 filter转换异常
最近在搞一个ssm+shiro的整合 用的maven tomcat插件 启动的时候报错,提示 maven org.springframework.web.filter.CharacterEncodin ...
- 也记一次性能优化:LINQ to SQL中Contains方法的优化
距离上一篇博文更新已经两个月过去了.在此,先表一表这两个月干了些啥: 世界那么大,我也想去看看.四月份的时候,我入职了上海的一家电商公司,职位是.NET高级开发工程师.工作一个月,最大的感受是比以前小 ...
- 记一次性能优化的心酸历程【Flask+Gunicorn+pytorch+多进程+线程池,一顿操作猛如虎】
您好,我是码农飞哥,感谢您阅读本文,欢迎一键三连哦. 本文只是记录我优化的心酸历程.无他,唯记录尔.....小伙伴们可围观,可打call,可以私信与我交流. 干货满满,建议收藏,需要用到时常看看. 小 ...
- [编织消息框架][设计协议]优化long,int转换
理论部分 一个long占8byte,大多数应用业数值不超过int每次传输多4byte会很浪费 有没有什么办法可以压缩long或int呢? 答案是有的,原理好简单,如果数值不超过int.max_valu ...
- Lazy<T>在Entity Framework中的性能优化实践(附源码)
在使用EF的过程中,导航属性的lazy load机制,能够减少对数据库的不必要的访问.只有当你使用到导航属性的时候,才会访问数据库.但是这个只是对于单个实体而言,而不适用于显示列表数据的情况. 这篇文 ...
- Lazy<T>在Entity Framework中的性能优化实践
Lazy<T>在Entity Framework中的性能优化实践(附源码) 2013-10-27 18:12 by JustRun, 328 阅读, 4 评论, 收藏, 编辑 在使用EF的 ...
随机推荐
- vue 打包成 apk 文件(修改路径)
第一个坑:文件引用路径 现在项目我们什么都没动,是初始化之后直接打包的状态,打开dist/index.htmnl文件整个网页都是一片空白的. 爬坑: 打开 config文件夹/index.js文件 a ...
- 关于exports 和 module.exports
本文来源为node.js社区附上链接 http://cnodejs.org/topic/5231a630101e574521e45ef8 require 用来加载代码,而 exports 和 modu ...
- | 插件下载陈磊SQL MD5 加密
简介:SQL MD5 加密 下述是 SQL Server 中 MD5加密 16位和32位的 ,)) ,ModifiedOn=null ; ,)) ,ModifiedOn=null ;
- ArraySegment 的使用 【转载】
本文转载自 http://www.cnblogs.com/overred/archive/2009/01/17/1359126.html ArraySegment顾名思义就是Array区块,数组的小抽 ...
- JNDI学习总结(1)——JNDI入门
JNDI是 Java 命名与目录接口(Java Naming and Directory Interface),在J2EE规范中是重要的规范之一,不少专家认为,没有透彻理解JNDI的意义和作用,就没有 ...
- [Docker 官方文档] 理解 Docker
http://segmentfault.com/a/1190000002609286 什么是 Docker? Docker 是一个用于开发.交付和执行应用的开放平台,Docker 设计用来更快的交付你 ...
- unity3d编程日志
2014/4/27 编写脚本的时候,加入了中文凝视,发现console面板有非常多不可思议的bug.查了一下发现是由于monodevelop脚本中文凝视报错,而英文凝视不会受影响. 解决方法:把凝视放 ...
- POJ 3461 Oulipo KMP算法题解
本题就是给出非常多对字符串,然后问一个字符串在另外一个字符串出现的次数. 就是所谓的Strstr函数啦. Leetcode有这道差点儿一模一样的题目. 使用KMP算法加速.算法高手必会的算法了. 另外 ...
- 使用框架的php假设使用定时服务Cronjob
工作须要用php开发了个监控的小程序,既然是监控就须要定时运行. 之前我用的是chrome加个定时刷新的小插件,放在server上执行.也能实现,就是别扭. 通用正规的做法应该是:linux上的Cro ...
- 求第k大的数(用到快速排序算法的思想)
//下面两种part效率比较:相同运算量下part比part2快5倍左右,part2写法简单但是效率低 #include "stdafx.h" #include <iostr ...