1. SELECT *
  2. FROM (SELECT pubformdat0_.id id332_,
  3. pubformdat0_.domain_id domain2_332_,
  4. pubformdat0_.process_id process3_332_,
  5. pubformdat0_.entity_id entity4_332_,
  6. pubformdat0_.file_type file5_332_,
  7. pubformdat0_.title title332_,
  8. pubformdat0_.word_no word7_332_,
  9. pubformdat0_.priority priority332_,
  10. pubformdat0_.secret_level secret9_332_,
  11. pubformdat0_.drafter drafter332_,
  12. pubformdat0_.drafter_name drafter11_332_,
  13. pubformdat0_.draft_dept draft12_332_,
  14. pubformdat0_.draft_deptname draft13_332_,
  15. pubformdat0_.draft_date draft14_332_,
  16. pubformdat0_.end_date end15_332_,
  17. pubformdat0_.arch_state arch16_332_,
  18. pubformdat0_.arch_fileid arch17_332_,
  19. pubformdat0_.gq_templateid gq18_332_,
  20. pubformdat0_.gw_templateid gw19_332_,
  21. pubformdat0_.edit_flag edit20_332_,
  22. pubformdat0_.delete_flag delete21_332_,
  23. pubformdat0_.operator operator332_,
  24. pubformdat0_.operate_date operate23_332_,
  25. pubformdat0_.file_security_level file24_332_,
  26. pubformdat0_.yj_flag yj25_332_,
  27. pubformdat0_.yj_user yj26_332_
  28. FROM wf_pub_form_data pubformdat0_
  29. WHERE 1 = 1
  30. AND pubformdat0_.id IN
  31. (SELECT DISTINCT pubformcas1_.form_id
  32. FROM wf_pub_form_case pubformcas1_
  33. WHERE pubformcas1_.case_id IN
  34. (SELECT to_char(caserun0_.id)
  35. FROM case_run caserun0_, workitem_run workitemru1_
  36. WHERE caserun0_.id = workitemru1_.caseid
  37. AND caserun0_.state = 2
  38. AND workitemru1_.performer IN ('300016/00415')
  39. AND workitemru1_.valid_flag = '0'
  40. UNION ALL
  41. SELECT to_char(caserun2_.id)
  42. FROM case_run caserun2_,
  43. workitem_history workitemhi3_
  44. WHERE caserun2_.id = workitemhi3_.caseid
  45. AND caserun2_.state = 2
  46. AND workitemhi3_.performer IN ('300016/00415')
  47. AND workitemhi3_.valid_flag = '0'))
  48. ORDER BY pubformdat0_.operate_date DESC)
  49. WHERE rownum <= 10;
  50. PLAN_TABLE_OUTPUT
  51. --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  52. Plan hash value: 1843931409
  53.  
  54. ------------------------------------------------------------------------------------------------------------------
  55. | Id | Operation | Name | Rows | Bytes |TempSpc| Cost (%CPU)| Time |
  56. ------------------------------------------------------------------------------------------------------------------
  57. | 0 | SELECT STATEMENT | | 10 | 11200 | | 230M (1)|769:57:46 |
  58. |* 1 | COUNT STOPKEY | | | | | | |
  59. | 2 | VIEW | | 718 | 785K| | 230M (1)|769:57:46 |
  60. |* 3 | SORT ORDER BY STOPKEY | | 718 | 281K| 696K| 230M (1)|769:57:46 |
  61. | 4 | NESTED LOOPS | | 718 | 281K| | 230M (1)|769:57:45 |
  62. | 5 | VIEW | VW_NSO_1 | 714 | 35700 | | 230M (1)|769:57:28 |
  63. | 6 | HASH UNIQUE | | 714 | 40698 | | | |
  64. |* 7 | FILTER | | | | | | |
  65. | 8 | TABLE ACCESS FULL | WF_PUB_FORM_CASE | 375K| 20M| | 1817 (1)| 00:00:22 |
  66. | 9 | UNION-ALL | | | | | | |
  67. | 10 | NESTED LOOPS | | 1 | 32 | | 261 (0)| 00:00:04 |
  68. | 11 | TABLE ACCESS BY INDEX ROWID| WORKITEM_RUN | 132 | 3168 | | 129 (0)| 00:00:02 |
  69. |* 12 | INDEX RANGE SCAN | IDX_WORKITEM_R_13 | 132 | | | 3 (0)| 00:00:01 |
  70. |* 13 | TABLE ACCESS BY INDEX ROWID| CASE_RUN | 1 | 8 | | 1 (0)| 00:00:01 |
  71. |* 14 | INDEX UNIQUE SCAN | PK_CASE_RUN | 1 | | | 0 (0)| 00:00:01 |
  72. | 15 | NESTED LOOPS | | 1 | 31 | | 368 (1)| 00:00:05 |
  73. | 16 | TABLE ACCESS BY INDEX ROWID| WORKITEM_HISTORY | 582 | 13386 | | 226 (0)| 00:00:03 |
  74. |* 17 | INDEX RANGE SCAN | IDX_WORKITEM_H_13 | 325 | | | 5 (0)| 00:00:01 |
  75. |* 18 | TABLE ACCESS BY INDEX ROWID| CASE_RUN | 1 | 8 | | 1 (0)| 00:00:01 |
  76. |* 19 | INDEX UNIQUE SCAN | PK_CASE_RUN | 1 | | | 0 (0)| 00:00:01 |
  77. | 20 | TABLE ACCESS BY INDEX ROWID | WF_PUB_FORM_DATA | 1 | 352 | | 2 (0)| 00:00:01 |
  78. |* 21 | INDEX UNIQUE SCAN | SYS_C0051297 | 1 | | | 1 (0)| 00:00:01 |
  79. ------------------------------------------------------------------------------------------------------------------
  80.  
  81. Predicate Information (identified by operation id):
  82. ---------------------------------------------------
  83.  
  84. 1 - filter(ROWNUM<=10)
  85. 3 - filter(ROWNUM<=10)
  86. 7 - filter( EXISTS ( (SELECT /*+ */ TO_CHAR("CASERUN0_"."ID") FROM "WORKITEM_RUN"
  87. "WORKITEMRU1_","CASE_RUN" "CASERUN0_" WHERE "CASERUN0_"."ID"="WORKITEMRU1_"."CASEID" AND
  88. "CASERUN0_"."STATE"=2 AND TO_CHAR("CASERUN0_"."ID")=:B1 AND "WORKITEMRU1_"."VALID_FLAG"='0' AND
  89. "WORKITEMRU1_"."PERFORMER"='300016/00415') UNION ALL (SELECT /*+ */ TO_CHAR("CASERUN2_"."ID") FROM
  90. "WORKITEM_HISTORY" "WORKITEMHI3_","CASE_RUN" "CASERUN2_" WHERE "CASERUN2_"."ID"="WORKITEMHI3_"."CASEID"
  91. AND "CASERUN2_"."STATE"=2 AND TO_CHAR("CASERUN2_"."ID")=:B2 AND "WORKITEMHI3_"."VALID_FLAG"='0' AND
  92. "WORKITEMHI3_"."PERFORMER"='300016/00415')))
  93. 12 - access("WORKITEMRU1_"."PERFORMER"='300016/00415' AND "WORKITEMRU1_"."VALID_FLAG"='0')
  94. 13 - filter("CASERUN0_"."STATE"=2)
  95. 14 - access("CASERUN0_"."ID"="WORKITEMRU1_"."CASEID")
  96. filter(TO_CHAR("CASERUN0_"."ID")=:B1)
  97. 17 - access("WORKITEMHI3_"."PERFORMER"='300016/00415' AND "WORKITEMHI3_"."VALID_FLAG"='0')
  98. 18 - filter("CASERUN2_"."STATE"=2)
  99. 19 - access("CASERUN2_"."ID"="WORKITEMHI3_"."CASEID")
  100. filter(TO_CHAR("CASERUN2_"."ID")=:B1)
  101. 21 - access("PUBFORMDAT0_"."ID"="$nso_col_1")
  102.  
  103. 50 rows selected.
  104.  
  105. 7 - filter( EXISTS ( (SELECT /*+ */ TO_CHAR("CASERUN0_"."ID") FROM "WORKITEM_RUN"
  106. "WORKITEMRU1_","CASE_RUN" "CASERUN0_" WHERE "CASERUN0_"."ID"="WORKITEMRU1_"."CASEID" AND
  107. "CASERUN0_"."STATE"=2 AND TO_CHAR("CASERUN0_"."ID")=:B1 AND "WORKITEMRU1_"."VALID_FLAG"='0' AND
  108. "WORKITEMRU1_"."PERFORMER"='300016/00415') UNION ALL (SELECT /*+ */ TO_CHAR("CASERUN2_"."ID") FROM
  109. "WORKITEM_HISTORY" "WORKITEMHI3_","CASE_RUN" "CASERUN2_" WHERE "CASERUN2_"."ID"="WORKITEMHI3_"."CASEID"
  110. AND "CASERUN2_"."STATE"=2 AND TO_CHAR("CASERUN2_"."ID")=:B2 AND "WORKITEMHI3_"."VALID_FLAG"='0' AND
  111. "WORKITEMHI3_"."PERFORMER"='300016/00415')))
  112.  
  113. pubformcas1_.case_id IN
  114. (SELECT to_char(caserun0_.id)
  115. FROM case_run caserun0_, workitem_run workitemru1_
  116. WHERE caserun0_.id = workitemru1_.caseid
  117. AND caserun0_.state = 2
  118. AND workitemru1_.performer IN ('300016/00415')
  119. AND workitemru1_.valid_flag = '0'
  120. UNION ALL
  121. SELECT to_char(caserun2_.id)
  122. FROM case_run caserun2_,
  123. workitem_history workitemhi3_
  124. WHERE caserun2_.id = workitemhi3_.caseid
  125. AND caserun2_.state = 2
  126. AND workitemhi3_.performer IN ('300016/00415')
  127. AND workitemhi3_.valid_flag = '0'))
  128.  
  129. 这里子查询解嵌套没有展开,改写如下:
  130. SELECT *
  131. FROM (SELECT pubformdat0_.id id332_, pubformdat0_.domain_id domain2_332_,
  132. pubformdat0_.process_id process3_332_,
  133. pubformdat0_.entity_id entity4_332_,
  134. pubformdat0_.file_type file5_332_,
  135. pubformdat0_.title title332_, pubformdat0_.word_no word7_332_,
  136. pubformdat0_.priority priority332_,
  137. pubformdat0_.secret_level secret9_332_,
  138. pubformdat0_.drafter drafter332_,
  139. pubformdat0_.drafter_name drafter11_332_,
  140. pubformdat0_.draft_dept draft12_332_,
  141. pubformdat0_.draft_deptname draft13_332_,
  142. pubformdat0_.draft_date draft14_332_,
  143. pubformdat0_.end_date end15_332_,
  144. pubformdat0_.arch_state arch16_332_,
  145. pubformdat0_.arch_fileid arch17_332_,
  146. pubformdat0_.gq_templateid gq18_332_,
  147. pubformdat0_.gw_templateid gw19_332_,
  148. pubformdat0_.edit_flag edit20_332_,
  149. pubformdat0_.delete_flag delete21_332_,
  150. pubformdat0_.operator operator332_,
  151. pubformdat0_.operate_date operate23_332_,
  152. pubformdat0_.file_security_level file24_332_,
  153. pubformdat0_.yj_flag yj25_332_, pubformdat0_.yj_user yj26_332_
  154. FROM wf_pub_form_data pubformdat0_
  155. WHERE 1 = 1
  156. AND pubformdat0_.id IN (SELECT DISTINCT pubformcas1_.form_id
  157. FROM wf_pub_form_case pubformcas1_
  158. /* WHERE pubformcas1_.case_id IN */
  159. where exists
  160. -----------------------------------------------------------------------
  161. (select null from (SELECT to_char(caserun0_.id) as id
  162. FROM case_run caserun0_,
  163. workitem_run workitemru1_
  164. WHERE caserun0_.id
  165. =
  166. workitemru1_.caseid
  167. AND caserun0_.state
  168. = 2
  169. AND workitemru1_.performer
  170. IN (
  171. '300016/00415'
  172. )
  173. AND workitemru1_.valid_flag
  174. = '0'
  175. UNION ALL
  176. SELECT to_char(
  177. caserun2_.id)
  178. FROM case_run caserun2_,
  179. workitem_history workitemhi3_
  180. WHERE caserun2_.id
  181. =
  182. workitemhi3_.caseid
  183. AND caserun2_.state
  184. = 2
  185. AND workitemhi3_.performer
  186. IN (
  187. '300016/00415'
  188. )
  189. AND workitemhi3_.valid_flag
  190. = '0'
  191. ) t
  192.  
  193. where pubformcas1_.case_id = t.id )
  194.  
  195. )
  196. ORDER BY pubformdat0_.operate_date DESC)
  197. WHERE rownum <= 10

子查询解嵌套in改写为exists的更多相关文章

  1. 子查询解嵌套not in 无法展开改写

    SQL> explain plan for select * from OPS$CZTEST1.SAVJ_ATOMJOURBAK where ((list_flag = '1' and prt_ ...

  2. SQL Server 之 子查询与嵌套查询

    当由where子句指定的搜索条件指向另一张表时,就需要使用子查询或嵌套查询. 1 子查询 子查询是一个嵌套在select.insert.update或delete语句或其他子查询中的查询.任何允许使用 ...

  3. ylb:子查询(嵌套子查询)和子查询(相关子查询)

    ylbtech-SQL Server:SQL Server-子查询(嵌套子查询)和子查询(相关子查询) SQL Server 子查询(嵌套子查询)和子查询(相关子查询). 1,ylb:1,子查询(嵌套 ...

  4. 10_MySQL DQL_子查询(嵌套的select)

    #子查询/* 含义:出现在其他语句中的select语句,称为子查询(内查询)           内部嵌套其他select语句的查询,称为主查询(外查询) 特点: 1.子查询都会放在小括号内 2.单行 ...

  5. 数据库开发基础-SQl Server 主键、外键、子查询(嵌套查询)

    主键 数据库主键是指表中一个列或列的组合,其值能唯一地标识表中的每一行.这样的一列或多列称为表的主键,通过它可强制表的实体完整性.当创建或更改表时可通过定义 PRIMARY KEY约束来创建主键.一个 ...

  6. Oracle子查询(嵌套查询)

    概念: 所谓子查询,即一个select语句中嵌套了另外的一个或者多个select语句 需求:查找和Smith同部门的所有员工的id和last_name 目标: 员工id,last_name from: ...

  7. java数据库编程之嵌套子查询及exists的使用

    第四章:高级查询(二) 4.1:exists和not exists子查询 4.1.1:exists子查询 用exists作为子查询的where条件 语法:select,,,,,,from 表名   w ...

  8. oracle 子查询详解 in和exists的区别

    sql允许多层嵌套,子查询是嵌套在其他查询中的查询.我们可以把子查询当做一张表来看到,即外层语句可以把内嵌的查询结果当做一张表使用. 子查询查询结果有三种情况 不返回查询记录.若子查询不返回记录则主查 ...

  9. sql子查询 嵌套SELECT语句

    嵌套SELECT语句也叫子查询,一个 SELECT 语句的查询结果能够作为另一个语句的输入值.子查询不但能够出现在Where子句中,也能够出现在from子句中,作为一个临时表使用,也能够出现在sele ...

随机推荐

  1. JQ动画事件

    1.会飞的li html: <ul id="ulL"> <li>中国</li> <li>美国</li> <li&g ...

  2. 周末充电之WPF(二 ) .窗口的布局

    登录窗口布局:[ Grid 布局 -Grid.RowDefinitions / Grid.ColumnDefinitions] 代码如下: <Window x:Class="login ...

  3. jfinal不能正确加载html网页,总是报错的解决方法

    今天自学jfinal,遇到一个很奇怪的问题,render("/index.html");总是报错. 仔细看错误日志,才发现原来是因为html网页放到了WEB-INF文件夹下面了,所 ...

  4. 基于ACE的定时器模板类

    ACETimerClockGenerator.h ClockGeneratorIF.h 在类中定义一个结构体,在结构体中定义一个函数. 在结构体中定义一个函数,这样做有什么好呢? TimerHandl ...

  5. Demo_张仕传_结构体考试-modify

    /* 题目: //声明一个结构体类型 struct _AdvTeacher { char *name; char *tile; int age; char *addr; char *p1; //系统预 ...

  6. thinkphp 整合 ucenter

    http://xcodebox.com/2013/06/8855.html 参考 1   ucenter源码目录下 /advanced/examples/api目录 copy到thinkphp项目根目 ...

  7. Trac与Apache的配合

    将Trac与Apache配合使用,需要用到mod_wsgi模块,首先Apache要安装负责wsgi的模块. def application(environ, start_request): #... ...

  8. 微信分享功能引入页面-控制分享时候调用的标题、图片、url和微信按钮隐藏显示控制

    1.设置分享调用的标题.图片.url预览. 2.控制右上角三个点按钮的隐藏显示(和底部工具栏的显示隐藏--未测试). 3.判断网页是否在微信中被调用. <!doctype html> &l ...

  9. jquery验证网址格式

    在input中输入网址,用jquery验证输入网址是否正确 <input type="text" name="input-web" class=" ...

  10. 有反斜杠时候,CakePHP往pgsql插入数据异常

    原始数据:INSERT INTO “public”.”tables” (“table”, “columns”) VALUES (‘table1\’, ‘{“col1″:false,”col2″:tru ...