子查询解嵌套in改写为exists
SELECT *
FROM (SELECT pubformdat0_.id id332_,
pubformdat0_.domain_id domain2_332_,
pubformdat0_.process_id process3_332_,
pubformdat0_.entity_id entity4_332_,
pubformdat0_.file_type file5_332_,
pubformdat0_.title title332_,
pubformdat0_.word_no word7_332_,
pubformdat0_.priority priority332_,
pubformdat0_.secret_level secret9_332_,
pubformdat0_.drafter drafter332_,
pubformdat0_.drafter_name drafter11_332_,
pubformdat0_.draft_dept draft12_332_,
pubformdat0_.draft_deptname draft13_332_,
pubformdat0_.draft_date draft14_332_,
pubformdat0_.end_date end15_332_,
pubformdat0_.arch_state arch16_332_,
pubformdat0_.arch_fileid arch17_332_,
pubformdat0_.gq_templateid gq18_332_,
pubformdat0_.gw_templateid gw19_332_,
pubformdat0_.edit_flag edit20_332_,
pubformdat0_.delete_flag delete21_332_,
pubformdat0_.operator operator332_,
pubformdat0_.operate_date operate23_332_,
pubformdat0_.file_security_level file24_332_,
pubformdat0_.yj_flag yj25_332_,
pubformdat0_.yj_user yj26_332_
FROM wf_pub_form_data pubformdat0_
WHERE 1 = 1
AND pubformdat0_.id IN
(SELECT DISTINCT pubformcas1_.form_id
FROM wf_pub_form_case pubformcas1_
WHERE pubformcas1_.case_id IN
(SELECT to_char(caserun0_.id)
FROM case_run caserun0_, workitem_run workitemru1_
WHERE caserun0_.id = workitemru1_.caseid
AND caserun0_.state = 2
AND workitemru1_.performer IN ('300016/00415')
AND workitemru1_.valid_flag = '0'
UNION ALL
SELECT to_char(caserun2_.id)
FROM case_run caserun2_,
workitem_history workitemhi3_
WHERE caserun2_.id = workitemhi3_.caseid
AND caserun2_.state = 2
AND workitemhi3_.performer IN ('300016/00415')
AND workitemhi3_.valid_flag = '0'))
ORDER BY pubformdat0_.operate_date DESC)
WHERE rownum <= 10;
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Plan hash value: 1843931409 ------------------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes |TempSpc| Cost (%CPU)| Time |
------------------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 10 | 11200 | | 230M (1)|769:57:46 |
|* 1 | COUNT STOPKEY | | | | | | |
| 2 | VIEW | | 718 | 785K| | 230M (1)|769:57:46 |
|* 3 | SORT ORDER BY STOPKEY | | 718 | 281K| 696K| 230M (1)|769:57:46 |
| 4 | NESTED LOOPS | | 718 | 281K| | 230M (1)|769:57:45 |
| 5 | VIEW | VW_NSO_1 | 714 | 35700 | | 230M (1)|769:57:28 |
| 6 | HASH UNIQUE | | 714 | 40698 | | | |
|* 7 | FILTER | | | | | | |
| 8 | TABLE ACCESS FULL | WF_PUB_FORM_CASE | 375K| 20M| | 1817 (1)| 00:00:22 |
| 9 | UNION-ALL | | | | | | |
| 10 | NESTED LOOPS | | 1 | 32 | | 261 (0)| 00:00:04 |
| 11 | TABLE ACCESS BY INDEX ROWID| WORKITEM_RUN | 132 | 3168 | | 129 (0)| 00:00:02 |
|* 12 | INDEX RANGE SCAN | IDX_WORKITEM_R_13 | 132 | | | 3 (0)| 00:00:01 |
|* 13 | TABLE ACCESS BY INDEX ROWID| CASE_RUN | 1 | 8 | | 1 (0)| 00:00:01 |
|* 14 | INDEX UNIQUE SCAN | PK_CASE_RUN | 1 | | | 0 (0)| 00:00:01 |
| 15 | NESTED LOOPS | | 1 | 31 | | 368 (1)| 00:00:05 |
| 16 | TABLE ACCESS BY INDEX ROWID| WORKITEM_HISTORY | 582 | 13386 | | 226 (0)| 00:00:03 |
|* 17 | INDEX RANGE SCAN | IDX_WORKITEM_H_13 | 325 | | | 5 (0)| 00:00:01 |
|* 18 | TABLE ACCESS BY INDEX ROWID| CASE_RUN | 1 | 8 | | 1 (0)| 00:00:01 |
|* 19 | INDEX UNIQUE SCAN | PK_CASE_RUN | 1 | | | 0 (0)| 00:00:01 |
| 20 | TABLE ACCESS BY INDEX ROWID | WF_PUB_FORM_DATA | 1 | 352 | | 2 (0)| 00:00:01 |
|* 21 | INDEX UNIQUE SCAN | SYS_C0051297 | 1 | | | 1 (0)| 00:00:01 |
------------------------------------------------------------------------------------------------------------------ Predicate Information (identified by operation id):
--------------------------------------------------- 1 - filter(ROWNUM<=10)
3 - filter(ROWNUM<=10)
7 - filter( EXISTS ( (SELECT /*+ */ TO_CHAR("CASERUN0_"."ID") FROM "WORKITEM_RUN"
"WORKITEMRU1_","CASE_RUN" "CASERUN0_" WHERE "CASERUN0_"."ID"="WORKITEMRU1_"."CASEID" AND
"CASERUN0_"."STATE"=2 AND TO_CHAR("CASERUN0_"."ID")=:B1 AND "WORKITEMRU1_"."VALID_FLAG"='0' AND
"WORKITEMRU1_"."PERFORMER"='300016/00415') UNION ALL (SELECT /*+ */ TO_CHAR("CASERUN2_"."ID") FROM
"WORKITEM_HISTORY" "WORKITEMHI3_","CASE_RUN" "CASERUN2_" WHERE "CASERUN2_"."ID"="WORKITEMHI3_"."CASEID"
AND "CASERUN2_"."STATE"=2 AND TO_CHAR("CASERUN2_"."ID")=:B2 AND "WORKITEMHI3_"."VALID_FLAG"='0' AND
"WORKITEMHI3_"."PERFORMER"='300016/00415')))
12 - access("WORKITEMRU1_"."PERFORMER"='300016/00415' AND "WORKITEMRU1_"."VALID_FLAG"='0')
13 - filter("CASERUN0_"."STATE"=2)
14 - access("CASERUN0_"."ID"="WORKITEMRU1_"."CASEID")
filter(TO_CHAR("CASERUN0_"."ID")=:B1)
17 - access("WORKITEMHI3_"."PERFORMER"='300016/00415' AND "WORKITEMHI3_"."VALID_FLAG"='0')
18 - filter("CASERUN2_"."STATE"=2)
19 - access("CASERUN2_"."ID"="WORKITEMHI3_"."CASEID")
filter(TO_CHAR("CASERUN2_"."ID")=:B1)
21 - access("PUBFORMDAT0_"."ID"="$nso_col_1") 50 rows selected. 7 - filter( EXISTS ( (SELECT /*+ */ TO_CHAR("CASERUN0_"."ID") FROM "WORKITEM_RUN"
"WORKITEMRU1_","CASE_RUN" "CASERUN0_" WHERE "CASERUN0_"."ID"="WORKITEMRU1_"."CASEID" AND
"CASERUN0_"."STATE"=2 AND TO_CHAR("CASERUN0_"."ID")=:B1 AND "WORKITEMRU1_"."VALID_FLAG"='0' AND
"WORKITEMRU1_"."PERFORMER"='300016/00415') UNION ALL (SELECT /*+ */ TO_CHAR("CASERUN2_"."ID") FROM
"WORKITEM_HISTORY" "WORKITEMHI3_","CASE_RUN" "CASERUN2_" WHERE "CASERUN2_"."ID"="WORKITEMHI3_"."CASEID"
AND "CASERUN2_"."STATE"=2 AND TO_CHAR("CASERUN2_"."ID")=:B2 AND "WORKITEMHI3_"."VALID_FLAG"='0' AND
"WORKITEMHI3_"."PERFORMER"='300016/00415'))) pubformcas1_.case_id IN
(SELECT to_char(caserun0_.id)
FROM case_run caserun0_, workitem_run workitemru1_
WHERE caserun0_.id = workitemru1_.caseid
AND caserun0_.state = 2
AND workitemru1_.performer IN ('300016/00415')
AND workitemru1_.valid_flag = '0'
UNION ALL
SELECT to_char(caserun2_.id)
FROM case_run caserun2_,
workitem_history workitemhi3_
WHERE caserun2_.id = workitemhi3_.caseid
AND caserun2_.state = 2
AND workitemhi3_.performer IN ('300016/00415')
AND workitemhi3_.valid_flag = '0')) 这里子查询解嵌套没有展开,改写如下:
SELECT *
FROM (SELECT pubformdat0_.id id332_, pubformdat0_.domain_id domain2_332_,
pubformdat0_.process_id process3_332_,
pubformdat0_.entity_id entity4_332_,
pubformdat0_.file_type file5_332_,
pubformdat0_.title title332_, pubformdat0_.word_no word7_332_,
pubformdat0_.priority priority332_,
pubformdat0_.secret_level secret9_332_,
pubformdat0_.drafter drafter332_,
pubformdat0_.drafter_name drafter11_332_,
pubformdat0_.draft_dept draft12_332_,
pubformdat0_.draft_deptname draft13_332_,
pubformdat0_.draft_date draft14_332_,
pubformdat0_.end_date end15_332_,
pubformdat0_.arch_state arch16_332_,
pubformdat0_.arch_fileid arch17_332_,
pubformdat0_.gq_templateid gq18_332_,
pubformdat0_.gw_templateid gw19_332_,
pubformdat0_.edit_flag edit20_332_,
pubformdat0_.delete_flag delete21_332_,
pubformdat0_.operator operator332_,
pubformdat0_.operate_date operate23_332_,
pubformdat0_.file_security_level file24_332_,
pubformdat0_.yj_flag yj25_332_, pubformdat0_.yj_user yj26_332_
FROM wf_pub_form_data pubformdat0_
WHERE 1 = 1
AND pubformdat0_.id IN (SELECT DISTINCT pubformcas1_.form_id
FROM wf_pub_form_case pubformcas1_
/* WHERE pubformcas1_.case_id IN */
where exists
-----------------------------------------------------------------------
(select null from (SELECT to_char(caserun0_.id) as id
FROM case_run caserun0_,
workitem_run workitemru1_
WHERE caserun0_.id
=
workitemru1_.caseid
AND caserun0_.state
= 2
AND workitemru1_.performer
IN (
'300016/00415'
)
AND workitemru1_.valid_flag
= '0'
UNION ALL
SELECT to_char(
caserun2_.id)
FROM case_run caserun2_,
workitem_history workitemhi3_
WHERE caserun2_.id
=
workitemhi3_.caseid
AND caserun2_.state
= 2
AND workitemhi3_.performer
IN (
'300016/00415'
)
AND workitemhi3_.valid_flag
= '0'
) t where pubformcas1_.case_id = t.id ) )
ORDER BY pubformdat0_.operate_date DESC)
WHERE rownum <= 10
子查询解嵌套in改写为exists的更多相关文章
- 子查询解嵌套not in 无法展开改写
SQL> explain plan for select * from OPS$CZTEST1.SAVJ_ATOMJOURBAK where ((list_flag = '1' and prt_ ...
- SQL Server 之 子查询与嵌套查询
当由where子句指定的搜索条件指向另一张表时,就需要使用子查询或嵌套查询. 1 子查询 子查询是一个嵌套在select.insert.update或delete语句或其他子查询中的查询.任何允许使用 ...
- ylb:子查询(嵌套子查询)和子查询(相关子查询)
ylbtech-SQL Server:SQL Server-子查询(嵌套子查询)和子查询(相关子查询) SQL Server 子查询(嵌套子查询)和子查询(相关子查询). 1,ylb:1,子查询(嵌套 ...
- 10_MySQL DQL_子查询(嵌套的select)
#子查询/* 含义:出现在其他语句中的select语句,称为子查询(内查询) 内部嵌套其他select语句的查询,称为主查询(外查询) 特点: 1.子查询都会放在小括号内 2.单行 ...
- 数据库开发基础-SQl Server 主键、外键、子查询(嵌套查询)
主键 数据库主键是指表中一个列或列的组合,其值能唯一地标识表中的每一行.这样的一列或多列称为表的主键,通过它可强制表的实体完整性.当创建或更改表时可通过定义 PRIMARY KEY约束来创建主键.一个 ...
- Oracle子查询(嵌套查询)
概念: 所谓子查询,即一个select语句中嵌套了另外的一个或者多个select语句 需求:查找和Smith同部门的所有员工的id和last_name 目标: 员工id,last_name from: ...
- java数据库编程之嵌套子查询及exists的使用
第四章:高级查询(二) 4.1:exists和not exists子查询 4.1.1:exists子查询 用exists作为子查询的where条件 语法:select,,,,,,from 表名 w ...
- oracle 子查询详解 in和exists的区别
sql允许多层嵌套,子查询是嵌套在其他查询中的查询.我们可以把子查询当做一张表来看到,即外层语句可以把内嵌的查询结果当做一张表使用. 子查询查询结果有三种情况 不返回查询记录.若子查询不返回记录则主查 ...
- sql子查询 嵌套SELECT语句
嵌套SELECT语句也叫子查询,一个 SELECT 语句的查询结果能够作为另一个语句的输入值.子查询不但能够出现在Where子句中,也能够出现在from子句中,作为一个临时表使用,也能够出现在sele ...
随机推荐
- java Spring配置数据单元
基本原理 - 容器和bean 在Spring中,那些组成你应用程序的主体(backbone)及由Spring IoC容器所管理的对象,被称之为bean. 简单地讲,bean就是由Spring容器初始化 ...
- using(){},Close(),Dispose()的区别
//用Close(),Dispose()方式关闭连接 string connString = "Data Source=(local);Initial Catalog=Linq;Integr ...
- 在VM虚拟机中安装centos7
- MVC小系列(十五)【MVC+ZTree实现对树的CURD及拖拽操作】
根据上一讲的可以加载一棵大树,这讲讲下如果操作这颗大树 <link href="../../Scripts/JQuery-zTree/css/zTreeStyle/zTreeStyle ...
- 注册dll
unit Unit1; interface uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, Syste ...
- 获取API返回值
//$return=getApiResult($url); // if ($return==200){ // //..... // } function getApiResult($url){ if( ...
- UIKit各类概述
1.UIAcceleration: 被叫做加速事件的一个UIAcceleration类的实例是用来代表即时的三维加速数据.为了接收重力加速度,要注册一个应用应用程序作为一个共享UIAccelerate ...
- zoj1873 Let it Bead
思路:polya裸题,如果是旋转,对于旋转i格的循环节长度len=lcm(i,n)/i,个数就是n/len=gcd(i,n):如果是翻转,奇数个点对称轴就是一个点一条边,那么循环节个数即n/2+1, ...
- (poj) 1751 Highways
Description The island nation of Flatopia is perfectly flat. Unfortunately, Flatopia has a very poor ...
- 在类成员函数后面加const
在看开源代码时,经常会看到在类的成员函数后面加const,之前了没有太关注过,近来闲来无事,就想起这件事,网上查了一下,大概明白了是怎么回事,这里引用CSDN愽文里的段话:“编译器会自动给每一个函数加 ...