子查询解嵌套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 ...
随机推荐
- JQ动画事件
1.会飞的li html: <ul id="ulL"> <li>中国</li> <li>美国</li> <li&g ...
- 周末充电之WPF(二 ) .窗口的布局
登录窗口布局:[ Grid 布局 -Grid.RowDefinitions / Grid.ColumnDefinitions] 代码如下: <Window x:Class="login ...
- jfinal不能正确加载html网页,总是报错的解决方法
今天自学jfinal,遇到一个很奇怪的问题,render("/index.html");总是报错. 仔细看错误日志,才发现原来是因为html网页放到了WEB-INF文件夹下面了,所 ...
- 基于ACE的定时器模板类
ACETimerClockGenerator.h ClockGeneratorIF.h 在类中定义一个结构体,在结构体中定义一个函数. 在结构体中定义一个函数,这样做有什么好呢? TimerHandl ...
- Demo_张仕传_结构体考试-modify
/* 题目: //声明一个结构体类型 struct _AdvTeacher { char *name; char *tile; int age; char *addr; char *p1; //系统预 ...
- thinkphp 整合 ucenter
http://xcodebox.com/2013/06/8855.html 参考 1 ucenter源码目录下 /advanced/examples/api目录 copy到thinkphp项目根目 ...
- Trac与Apache的配合
将Trac与Apache配合使用,需要用到mod_wsgi模块,首先Apache要安装负责wsgi的模块. def application(environ, start_request): #... ...
- 微信分享功能引入页面-控制分享时候调用的标题、图片、url和微信按钮隐藏显示控制
1.设置分享调用的标题.图片.url预览. 2.控制右上角三个点按钮的隐藏显示(和底部工具栏的显示隐藏--未测试). 3.判断网页是否在微信中被调用. <!doctype html> &l ...
- jquery验证网址格式
在input中输入网址,用jquery验证输入网址是否正确 <input type="text" name="input-web" class=" ...
- 有反斜杠时候,CakePHP往pgsql插入数据异常
原始数据:INSERT INTO “public”.”tables” (“table”, “columns”) VALUES (‘table1\’, ‘{“col1″:false,”col2″:tru ...