需要优化的SQL
SELECT * FROM (SELECT A.*, ROWNUM R FROM (SELECT DISTINCT A.NDOCID AS NDOCID, TO_CHAR(NVL(A.DMODIFYDATE, A.DCREATEDATE), 'yyyy-MM-dd hh24:mi:ss') AS DMODIFYDATE, NVL(A.CURTITLE, ' ') AS CTITLE, A.DMODIFYDATE AS DM, A.DCREATEDATE, A.CURTITLE, A.NPROCID, A.NPROCSTATUS, A.NDOCSORTID, A.NMANAGERID, GW.CDOCPRIORITY, GW.CFWDW, GW.WENHAO, GW.CDOCUTYPE, COUNT(A.NDOCID) OVER() AS ROWNUMBER FROM WF_DOC_GW A, (SELECT NDOCID, NJJCD, CBT AS CTITLE, CFWDW, NVL(CDOCFROM, '本单位发文') AS CDOCFROM, NVL(CDOCPRIORITY, 100) AS CDOCPRIORITY, NVL(CFWZH, '无文号') AS WENHAO, CDOCUTYPE, CFWYDW FROM WF_DOC_GW_SHOUWEN SW UNION ALL SELECT NDOCID, NJJCD, CBT AS CTITLE, CFWDW, NVL(CDOCFROM, '本单位发文') AS CDOCFROM, NVL(CDOCPRIORITY, 0) AS CDOCPRIORITY, NVL(CWENHAO, '无文号') AS WENHAO, CDOCUTYPE, CFWYDW FROM WF_DOC_GW_FAWEN FW) GW WHERE ((A.NPROCID = 20 AND A.NPROCSTATUS = 1) OR (A.NPROCID <> 20)) AND (A.NSTATE = 0 OR (A.NSTATE = 2 AND A.NDOCSORTID = 1)) AND A.NDOCSORTID IN (1, 2) AND ((INSTR(',' || A.CPROCUSERLIST || ',', ',' || '4301' || ',') > 0 AND A.NDOCID NOT IN (SELECT GI.SRC_NDOCID FROM WF_DOC_GW_INNER GI WHERE GI.SRC_USERID = 4301 AND GI.RETURNSTATUS IS NULL AND GI.SRC_NDOCID IS NOT NULL)) OR A.NPROCUID = 4301) AND (A.NMSGID = 0 OR (A.NMSGID IS NOT NULL AND A.NFWQBOPT = 10)) AND GW.NDOCID = A.NDOCID ORDER BY A.DMODIFYDATE DESC, GW.CDOCPRIORITY DESC) A WHERE ROWNUM <= 13) B WHERE R > 0
执行计划
------------------------------------------------------------------------- | Id | Operation | Name | E-Rows | ------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | | |* 1 | VIEW | | 13 | |* 2 | COUNT STOPKEY | | | | 3 | VIEW | | 261 | |* 4 | SORT UNIQUE STOPKEY | | 261 | | 5 | WINDOW BUFFER | | 261 | |* 6 | FILTER | | | |* 7 | HASH JOIN | | 90557 | |* 8 | TABLE ACCESS FULL | WF_DOC_GW | 84010 | | 9 | VIEW | | 261K| | 10 | UNION-ALL | | | | 11 | TABLE ACCESS FULL | WF_DOC_GW_SHOUWEN | 242K| | 12 | TABLE ACCESS FULL | WF_DOC_GW_FAWEN | 18876 | |* 13 | TABLE ACCESS BY INDEX ROWID| WF_DOC_GW_INNER | 1 | |* 14 | INDEX RANGE SCAN | IDX_INNER_SRCDOCID | 2 | -------------------------------------------------------------------------
Predicate Information (identified by operation id): --------------------------------------------------- 1 - filter("R">0) 2 - filter(ROWNUM<=13) 4 - filter(ROWNUM<=13) 6 - filter(((INSTR(','||"A"."CPROCUSERLIST"||',',',4301,')>0 AND IS NULL) OR "A"."NPROCUID"=4301)) 8 - filter((("A"."NSTATE"=0 OR ("A"."NSTATE"=2 AND "A"."NDOCSORTID"=1)) AND ("A"."NPROCID"<>20 OR ("A"."NPROCSTATUS"=1 AND "A"."NPROCID"=20)) AND ("A"."NMSGID"=0 OR ("A"."NFWQBOPT"=10 AND "A"."NMSGID" IS NOT NULL)) AND INTERNAL_FUNCTION("A"."NDOCSORTID"))) 12 - access("NDOCID"="A"."NDOCID") 14 - access("NDOCID"="A"."NDOCID") 15 - filter(("GI"."SRC_USERID"=4301 AND "GI"."RETURNSTATUS" IS NULL)) 16 - access("GI"."SRC_NDOCID"=:B1) filter("GI"."SRC_NDOCID" IS NOT NULL)
该条SQL执行后的结果集只有2条数据,WF_DOC_GW_SHOUWEN数据量有24万,NDOCID是主键,从执行计划看,走的是全表扫描,和预期结果不符合,应该走的是唯一索引才对,优化的思路是先关联WF_DOC_GW和WF_DOC_GW_INNER,计算出结果集后,再关联WF_DOC_GW_SHOUWEN,这样就会走唯一索引,使用push_subq可以达到想要到想过,修改后的SQL如下
SELECT * FROM (SELECT A.*, ROWNUM R FROM (SELECT /*+ push_subq(@tmp)*/ DISTINCT A.NDOCID AS NDOCID, TO_CHAR(NVL(A.DMODIFYDATE, A.DCREATEDATE), 'yyyy-MM-dd hh24:mi:ss') AS DMODIFYDATE, NVL(A.CURTITLE, ' ') AS CTITLE, A.DMODIFYDATE AS DM, A.DCREATEDATE, A.CURTITLE, A.NPROCID, A.NPROCSTATUS, A.NDOCSORTID, A.NMANAGERID, GW.CDOCPRIORITY, GW.CFWDW, GW.WENHAO, GW.CDOCUTYPE, COUNT(A.NDOCID) OVER() AS ROWNUMBER FROM WF_DOC_GW A, (SELECT NDOCID, NJJCD, CBT AS CTITLE, CFWDW, NVL(CDOCFROM, '本单位发文') AS CDOCFROM, NVL(CDOCPRIORITY, 100) AS CDOCPRIORITY, NVL(CFWZH, '无文号') AS WENHAO, CDOCUTYPE, CFWYDW FROM WF_DOC_GW_SHOUWEN SW UNION ALL SELECT NDOCID, NJJCD, CBT AS CTITLE, CFWDW, NVL(CDOCFROM, '本单位发文') AS CDOCFROM, NVL(CDOCPRIORITY, 0) AS CDOCPRIORITY, NVL(CWENHAO, '无文号') AS WENHAO, CDOCUTYPE, CFWYDW FROM WF_DOC_GW_FAWEN FW) GW WHERE ((A.NPROCID = 20 AND A.NPROCSTATUS = 1) OR (A.NPROCID <> 20)) AND (A.NSTATE = 0 OR (A.NSTATE = 2 AND A.NDOCSORTID = 1)) AND A.NDOCSORTID IN (1, 2) AND ((INSTR(',' || A.CPROCUSERLIST || ',', ',' || '4301' || ',') > 0 AND A.NDOCID NOT IN (SELECT /*+ qb_name(tmp)*/ GI.SRC_NDOCID FROM WF_DOC_GW_INNER GI WHERE GI.SRC_USERID = 4301 AND GI.RETURNSTATUS IS NULL AND GI.SRC_NDOCID IS NOT NULL)) OR A.NPROCUID = 4301) AND (A.NMSGID = 0 OR (A.NMSGID IS NOT NULL AND A.NFWQBOPT = 10)) AND GW.NDOCID = A.NDOCID ORDER BY A.DMODIFYDATE DESC, GW.CDOCPRIORITY DESC) A WHERE ROWNUM <= 13) B WHERE R > 0
------------------------------------------------------------------------------------------------------------ | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | ------------------------------------------------------------------------------------------------------------ | 0 | SELECT STATEMENT | | 13 | 9984 | 2518 (1)| 00:00:31 | |* 1 | VIEW | | 13 | 9984 | 2518 (1)| 00:00:31 | |* 2 | COUNT STOPKEY | | | | | | | 3 | VIEW | | 244 | 179K| 2518 (1)| 00:00:31 | |* 4 | SORT UNIQUE STOPKEY | | 244 | 63928 | 2517 (1)| 00:00:31 | | 5 | WINDOW BUFFER | | 244 | 63928 | 2518 (1)| 00:00:31 | | 6 | NESTED LOOPS | | 244 | 63928 | 2516 (1)| 00:00:31 | |* 7 | TABLE ACCESS FULL | WF_DOC_GW | 242 | 27588 | 1547 (2)| 00:00:19 | |* 8 | TABLE ACCESS BY INDEX ROWID | WF_DOC_GW_INNER | 1 | 17 | 2 (0)| 00:00:01 | |* 9 | INDEX RANGE SCAN | IDX_INNER_SRCDOCID | 2 | | 1 (0)| 00:00:01 | | 10 | VIEW | | 1 | 148 | 4 (0)| 00:00:01 | | 11 | UNION ALL PUSHED PREDICATE | | | | | | | 12 | TABLE ACCESS BY INDEX ROWID| WF_DOC_GW_SHOUWEN | 1 | 49 | 2 (0)| 00:00:01 | |* 13 | INDEX UNIQUE SCAN | PK_WF_DOC_GW_SHOUWEN | 1 | | 1 (0)| 00:00:01 | | 14 | TABLE ACCESS BY INDEX ROWID| WF_DOC_GW_FAWEN | 1 | 38 | 2 (0)| 00:00:01 | |* 15 | INDEX UNIQUE SCAN | PK_WF_DOC_GW_FAWEN | 1 | | 1 (0)| 00:00:01 |
优化前的逻辑读是12000,优化后的逻辑读降到了5000,还是蛮有效果的
相关推荐
- `NO_PUSH_SUBQ`:指示不将子查询下推到表访问操作。 - `PX_JOIN_FILTER`:指示并行执行时的连接过滤。 - `NO_PX_JOIN_FILTER`:指示并行执行时不使用连接过滤。 - `NO_XML_QUERY_REWRITE`:指示不进行XML查询...
- **PUSH_JOIN_PRED(v)** 和 **NO_PUSH_JOIN_PRED(v)**: 控制JOIN谓词是否推入视图。 ##### 5. 读取方式 - **FULL(tab)**: 对表执行全表扫描。 - **CACHE(tab)**: 如果表大小小于`CACHE_SIZE_THRESHOLD`参数设置的...
在IT行业中,网络建模与仿真工具是至关重要的,它们帮助我们理解网络性能,优化设计并预测潜在问题。OPNET(Optimized Network Engineering Tool)就是这样一款强大的工具,它提供了详尽的网络性能分析和建模功能。...
3. **索引提示**:查询开头的`/*+ PUSH_SUBQ */`是一个索引提示,它告诉数据库优化器如何处理子查询,以提高查询性能。 ### 结论 通过上述SQL查询,我们可以有效地监控和分析数据库中存储过程的执行情况及其对系统...
- **注意事项**: 使用了提示`/*+PUSH_SUBQ*/`来优化查询性能,并通过输入参数`&sid`来指定查询的会话SID。 ### 4. 查询对象被访问的情况 **SQL语句**: ```sql SELECT p.Spid, s.Sid, s.Serial# Serial_Num, s....
SELECT /*+PUSH_SUBQ*/ Command_Type, Sql_Text, Sharable_Mem, Persistent_Mem, Runtime_Mem, Sorts, Version_Count, Loaded_Versions, Open_Versions, Users_Opening, Executions, Users_Executing, Loads, ...
对于可能遇到该bug的用户,文档提供了一个解决方案:为了避免ORA-1790错误,可以将初始化参数"_optimizer_unnest_corr_set_subq"设置为FALSE。这可以作为一种避免错误的方法,但请注意这不一定能解决所有性能问题,...
4. **对象优先原则**:在函数名中,对象名称总是放在动作之前,如`attr_set`表示设置属性(`attr`),`subq_flush`表示清空子队列(`subq`)。 ##### 1.2 参数类型 OPNET中的核心函数使用的参数类型除了标准的C/C++...
例如,`op_subq_create()`用于创建一个新的子队列,`op_subq_delete()`用于删除一个子队列。 **2.12 统计量函数集** 统计量函数集提供了创建、更新和查询统计数据的方法。例如,`op_stat_create()`用于创建一个新...
- **对象与动作**:在函数命名中,对象通常放在动作之前,例如 `attr_set` 和 `subq_flush`,其中 `attr` 和 `subq` 是操作的对象,`set` 和 `flush` 是执行的动作。 ##### 1.2 参数类型 OPNET Modeler 提供了一...
- 当需要使用更复杂的 SQL 查询时,可以直接编写 SQL 并执行: ```python from sqlalchemy import text result = session.execute(text("SELECT * FROM users WHERE name=:name"), {'name': 'John'}) ``` - **...
##### 使用纯 SQL 有时可能需要执行更复杂的 SQL 查询,可以通过 `text()` 函数实现。 ```python >>> from sqlalchemy import text >>> stmt = text("SELECT * FROM users WHERE name=:name") >>> ed_user = session...
它为SublimeText使用了和。 ## Installation以下内容会将此存储库的文件克隆到~/Library/Application Support/Sublime Text 2/Packages/User 。 因此,您无需先安装Solarized和Soda。 $ git clone ...
子队列函数集处理子队列的管理,如`op_subq_create()`用于创建新的子队列。 **2.12 统计量函数集** 统计量函数集用于收集和报告仿真过程中的统计信息,如`op_stat_create()`用于创建新的统计量。 以上概述了OPNET...
在本文中,我们使用的操作系统是 64 位的 CentOS 6.2,服务器采用的是 Darwin Streaming Server 6.0.3,摄像头数据源用 FFMPEG 0.6 进行采集。FFMPEG 是一个功能强大的开源多媒体处理工具,可以对音频和视频进行采集...
- 通过 `subq $32, %rsp` 分配了32个字节的栈空间,用于存储局部变量。 5. 字符串与数据段: - `.LC0` 定义了一个标签,用于引用字符串常量 "computer"。 - `.section .rodata` 定义了一个只读数据段,其中存放...
根据给定文件信息,可以提取出以下几个关键知识点: 1. Word宏编程基础: - Word宏是利用Visual ...此外,还能够了解如何优化Word宏的使用体验,例如通过设置快捷键来快速执行宏命令,以及如何确保宏的安全运行。
subq $16, %rsp movl $.LC0, %edi call printf xorl %eax, %eax leave .cfi_def_cfa 7, 8 ret .cfi_endproc .LFE0: .size _main, .-_main .Letext0: .LC0: .string "Hello World!\n" ``` 通过上述汇编...
例如,程序SUBQ2-71至SUBQ2-76被用于基于串列输入数据的坐标反算边长与方位计算,而SUBQ2-81至SUBQ2-87等程序则用于线元法任意路线与道曲线坐标正反算程序和放样参数的计算。 书中还提到了程序功能说明,例如QH3-3H...