真實世界SQL最佳化案例2_訪問路徑最佳化

orastar發表於2017-09-12

1.  問題描述

生成資料庫AWR報告:822日  1000 1800TOP1 SQL: 3g5996z6awjux,執行次數:217677次,每次執行時間7.38秒,佔用資料庫總資源(elapsed time):43.22%。


2.  問題分析

SQL語句:

繫結變數從v$sql_bind_capture獲取

點選(此處)摺疊或開啟

  1. SELECT *
  2.   FROM (
  3.   SELECT LI.*,
  4.                CASE
  5.                  WHEN LI.OVERDUED_NE = 1 OR LI.OVERDUED_NE = 3 THEN
  6.                   1
  7.                  WHEN LI.OVERDUED_NE = 0 OR LI.OVERDUED_NE = 2 THEN
  8.                   CASE
  9.                     WHEN E.SUSPEND_FLAG = 0 THEN
  10.                      CASE
  11.                        WHEN SYSTIMESTAMP >= E.TARGET_OVERDUE_MINTIME THEN
  12.                         1
  13.                        ELSE
  14.                         0
  15.                      END
  16.                     WHEN E.SUSPEND_FLAG = 1 THEN
  17.                      CASE
  18.                        WHEN E.SUSPEND_TIME >= E.TARGET_OVERDUE_MINTIME THEN
  19.                         1
  20.                        ELSE
  21.                         0
  22.                      END
  23.                     ELSE
  24.                      0
  25.                   END
  26.                  ELSE
  27.                   0
  28.                END OVERDUED,
  29.                CASE
  30.                  WHEN E.TARGET_OVERDUE_MINTIME IS NULL THEN
  31.                   LI.TARGET_TIME_NE
  32.                  WHEN LI.TARGET_TIME_NE IS NULL THEN
  33.                   E.TARGET_OVERDUE_MINTIME
  34.                  WHEN E.TARGET_OVERDUE_MINTIME <= LI.TARGET_TIME_NE THEN
  35.                   E.TARGET_OVERDUE_MINTIME
  36.                  ELSE
  37.                   LI.TARGET_TIME_NE
  38.                END TARGET_TIME,
  39.                FTM.WORKFORM_TYPE_KIND
  40.           FROM (
  41.           SELECT /*+INDEX(F IDX_WORKFORM_PROCINST_ID)*/
  42.                  WF.PROC_INSTANCE_ID,
  43.                  WF.ACTIVITY_INS_ID,
  44.                  WF.WORKITEM_INS_ID,
  45.                  WF.NAME,
  46.                  WF.CURRENT_STATE,
  47.                  WF.COMPLETE_TIME,
  48.                  WF.CREATE_TIME,
  49.                  WF.LIMIT_TIME,
  50.                  WF.APP_URL,
  51.                  WF.USER_NAME,
  52.                  WF.USER_ID,
  53.                  WF.USER_ENTITY_TYPE,
  54.                  WF.USER_ENTITY_NAME,
  55.                  WF.USER_ENTITY_ID,
  56.                  WF.PARTICIPANT_TYPE,
  57.                  WF.SEND_TYPE,
  58.                  WF.OVERDUED AS OVERDUED_NE,
  59.                  WF.EXT_PROP,
  60.                  WF.FLOW_DIRECTION,
  61.                  WF.BUSINESSKEY,
  62.                  WF.DEPART_ID,
  63.                  F.INSTANCE_ID AS WI_INSTANCE_ID,
  64.                  F.INSTANCE_NAME AS WI_INSTANCE_NAME,
  65.                  F.WORKFORM_TYPE AS WI_WORKFORM_TYPE,
  66.                  F.BUILDER AS WI_BUILDER,
  67.                  F.START_TIME AS WI_CREATE_TIME,
  68.                  F.INSTANCE_STATUS AS WI_INSTANCE_STATUS,
  69.                  F.BUSINESS AS WI_BUSINESS,
  70.                  F.KEYDATA_ID AS WI_KEYDATA_ID,
  71.                  F.IS_FLOW AS WI_IS_FLOW,
  72.                  F.ATTR1 AS WI_ATTR1,
  73.                  F.DEPT_ID AS WI_DEPT_ID,
  74.                  '' AS WT_DEPT_ID,
  75.                  WF.CURRENT_STATE AS WT_WORKTASK_STATUS,
  76.                  NULL AS WT_TARGET_TIME,
  77.                  '' AS WT_LINK_URL,
  78.                  '' AS WT_LINK_PARAM,
  79.                  '' AS WT_IS_BATCH,
  80.                  U.REAL_NAME AS WI_BUILDER_REALNAME,
  81.                  NULL AS HOWLONG_WILL_OVERDUE,
  82.                  NULL AS HOWLONG_OVERDUED,
  83.                  '' AS ACTIVITY_TMP_ID,
  84.                  O.TIME_OUT_TIME AS TARGET_TIME_NE,
  85.                  B.APPROVAL_STATUS AS BE_APPROVAL_STATUS,
  86.                  ORG.ORG_NO,
  87.                  ORG.ORG_NAME,
  88.                  '' AS VIEW_FLAGS
  89.                   FROM EPSA_SN.SA_WORKFORM_INST F,
  90.                        (SELECT W.*
  91.                           FROM EPSA_SN.RT_WORKITEMINST W
  92.                          WHERE (W.CURRENT_STATE = 1 OR W.CURRENT_STATE = 2 OR
  93.                                W.CURRENT_STATE = 3)
  94.                            AND W.USER_ID = '153812'
  95.                            AND W.PARTICIPANT_TYPE = 0
  96.                         UNION ALL
  97.                         SELECT W.*
  98.                           FROM EPSA_SN.RT_WORKITEMINST W, EPSA_SN.SA_BROLE_USER R
  99.                          WHERE (W.CURRENT_STATE = 1 OR W.CURRENT_STATE = 2 OR
  100.                                W.CURRENT_STATE = 3)
  101.                            AND W.USER_ID = R.ROLE_ID
  102.                            AND R.USER_ID = '153812'
  103.                            AND W.PARTICIPANT_TYPE = 1) WF,
  104.                         EPSA_SN.SA_USER U,
  105.                        (SELECT * FROM EPSA_SN.RT_OVERTIME_DEAL WHERE TIMER_TYPE = 1) O,
  106.                         EPSA_SN.SA_WF_BUSINESS_EXT B,
  107.                         EPSA_SN.SA_DEPT D,
  108.                         EPSA_SN.SA_ORG ORG
  109.                  WHERE F.PROCINST_ID = WF.PROC_INSTANCE_ID --F.PROCINST_ID
  110.                    AND WF.WORKITEM_INS_ID = O.INSTANCE_ID(+)
  111.                    AND F.BUILDER = U.USER_ID(+) --F.BUILDER
  112.                    AND U.DEPT_ID = D.DEPT_ID(+)
  113.                    AND D.ORG_NO = ORG.ORG_NO(+)
  114.                    AND WF.WORKITEM_INS_ID = B.WORKITEM_ID(+)
  115.                    AND (WF.PARTICIPANT_TYPE = 0 OR
  116.                        (WF.PARTICIPANT_TYPE = 1 AND
  117.                        ((WF.DEPART_ID IS NOT NULL AND
  118.                        ((WF.DEPART_ID LIKE '*61102|201181|6140143000|6140143009%') OR
  119.                        ('61102|201181|6140143000|6140143009' LIKE (WF.DEPART_ID || '%')) OR
  120.                        ('$61102|201181|6140143000|6140143009' = WF.DEPART_ID))) OR
  121.                        ((WF.DEPART_ID IS NULL OR Wf.DEPART_ID = '') AND
  122.                        ((F.DEPT_ID LIKE '*61102|201181|6140143000|6140143009%') OR --F.DEPT_ID
  123.                        ('61102|201181|6140143000|6140143009' LIKE (F.DEPT_ID || '%')) OR ('$61102|201181|6140143000|6140143009' = F.DEPT_ID))))))
  124.                 UNION ALL
  125.                 SELECT /*+INDEX(F IDX_WORKFORM_PROCINST_ID)*/
  126.                  WF.PROC_INSTANCE_ID,
  127.                  WF.ACTIVITY_INS_ID,
  128.                  WF.WORKITEM_INS_ID,
  129.                  WF.NAME,
  130.                  WF.CURRENT_STATE,
  131.                  WF.COMPLETE_TIME,
  132.                  WF.CREATE_TIME,
  133.                  WF.LIMIT_TIME,
  134.                  WF.APP_URL,
  135.                  WF.USER_NAME,
  136.                  WF.USER_ID,
  137.                  WF.USER_ENTITY_TYPE,
  138.                  WF.USER_ENTITY_NAME,
  139.                  WF.USER_ENTITY_ID,
  140.                  WF.PARTICIPANT_TYPE,
  141.                  WF.SEND_TYPE,
  142.                  WF.OVERDUED AS OVERDUED_NE,
  143.                  WF.EXT_PROP,
  144.                  WF.FLOW_DIRECTION,
  145.                  WF.BUSINESSKEY,
  146.                  WF.DEPART_ID,
  147.                  F.INSTANCE_ID AS WI_INSTANCE_ID,
  148.                  F.INSTANCE_NAME AS WI_INSTANCE_NAME,
  149.                  F.WORKFORM_TYPE AS WI_WORKFORM_TYPE,
  150.                  F.BUILDER AS WI_BUILDER,
  151.                  F.START_TIME AS WI_CREATE_TIME,
  152.                  F.INSTANCE_STATUS AS WI_INSTANCE_STATUS,
  153.                  F.BUSINESS AS WI_BUSINESS,
  154.                  F.KEYDATA_ID AS WI_KEYDATA_ID,
  155.                  F.IS_FLOW AS WI_IS_FLOW,
  156.                  F.ATTR1 AS WI_ATTR1,
  157.                  F.DEPT_ID AS WI_DEPT_ID,
  158.                  '' AS WT_DEPT_ID,
  159.                  WF.CURRENT_STATE AS WT_WORKTASK_STATUS,
  160.                  NULL AS WT_TARGET_TIME,
  161.                  '' AS WT_LINK_URL,
  162.                  '' AS WT_LINK_PARAM,
  163.                  '' AS WT_IS_BATCH,
  164.                  U.REAL_NAME AS WI_BUILDER_REALNAME,
  165.                  NULL AS HOWLONG_WILL_OVERDUE,
  166.                  NULL AS HOWLONG_OVERDUED,
  167.                  '' AS ACTIVITY_TMP_ID,
  168.                  O.TIME_OUT_TIME AS TARGET_TIME_NE,
  169.                  B.APPROVAL_STATUS AS BE_APPROVAL_STATUS,
  170.                  ORG.ORG_NO,
  171.                  ORG.ORG_NAME,
  172.                  '' AS VIEW_FLAGS
  173.                   FROM EPSA_SN.SA_WORKFORM_INST F,
  174.                        (SELECT W.*
  175.                           FROM EPSA_SN.RT_WORKITEMINST W
  176.                          WHERE (W.CURRENT_STATE = 1 OR W.CURRENT_STATE = 2 OR
  177.                                W.CURRENT_STATE = 3)
  178.                            AND W.USER_ID = '153812'
  179.                            AND W.PARTICIPANT_TYPE = 0
  180.                         UNION ALL
  181.                         SELECT W.*
  182.                           FROM EPSA_SN.RT_WORKITEMINST W, EPSA_SN.SA_BROLE_USER R
  183.                          WHERE (W.CURRENT_STATE = 1 OR W.CURRENT_STATE = 2 OR
  184.                                W.CURRENT_STATE = 3)
  185.                            AND W.USER_ID = R.ROLE_ID
  186.                            AND R.USER_ID = '153812'
  187.                            AND W.PARTICIPANT_TYPE = 1) WF,
  188.                         EPSA_SN.SA_USER U,
  189.                         EPSA_SN.RT_PROCESSINSTANCE P,
  190.                        (SELECT * FROM EPSA_SN.RT_OVERTIME_DEAL WHERE TIMER_TYPE = 1) O,
  191.                         EPSA_SN.SA_WF_BUSINESS_EXT B,
  192.                         EPSA_SN.SA_DEPT D,
  193.                         EPSA_SN.SA_ORG ORG
  194.                  WHERE WF.PROC_INSTANCE_ID = P.PROC_INSTANCE_ID
  195.                    AND P.PARENT_PROCINC_ID IS NOT NULL
  196.                    AND F.PROCINST_ID = P.PARENT_PROCINC_ID
  197.                    AND F.BUILDER = U.USER_ID(+)
  198.                    AND U.DEPT_ID = D.DEPT_ID(+)
  199.                    AND D.ORG_NO = ORG.ORG_NO(+)
  200.                    AND WF.WORKITEM_INS_ID = O.INSTANCE_ID(+)
  201.                    AND WF.WORKITEM_INS_ID = B.WORKITEM_ID(+)
  202.                    AND (WF.PARTICIPANT_TYPE = 0 OR
  203.                        (WF.PARTICIPANT_TYPE = 1 AND
  204.                        ((WF.DEPART_ID IS NOT NULL AND
  205.                        ((WF.DEPART_ID LIKE '*61102|201181|6140143000|6140143009%') OR
  206.                        ('61102|201181|6140143000|6140143009' LIKE (WF.DEPART_ID || '%')) OR
  207.                        ('$61102|201181|6140143000|6140143009' = WF.DEPART_ID))) OR
  208.                        ((WF.DEPART_ID IS NULL OR Wf.DEPART_ID = '') AND
  209.                        ((F.DEPT_ID LIKE '*61102|201181|6140143000|6140143009%') OR
  210.                        ('61102|201181|6140143000|6140143009' LIKE (F.DEPT_ID || '%')) OR
  211.                        ('$61102|201181|6140143000|6140143009' = F.DEPT_ID))))))
  212.                    AND NOT EXISTS
  213.                  (SELECT 1
  214.                           FROM EPSA_SN.SA_WORKFORM_INST RF
  215.                          WHERE WF.PROC_INSTANCE_ID = RF.PROCINST_ID)
  216.                          ) LI,
  217.                 EPSA_SN.SA_WF_WORKFORM_TYPE_MAP FTM,
  218.                (SELECT ACT_INST_ID,
  219.                        SUSPEND_FLAG,
  220.                        MIN(TARGET_OVERDUE_MINTIME) AS TARGET_OVERDUE_MINTIME,
  221.                        MIN(SUSPEND_TIME) AS SUSPEND_TIME
  222.                   FROM (SELECT A.ACT_INST_ID, B.*
  223.                           FROM EPSA_SN.SA_WF_EXAM_ACT_INST A, EPSA_SN.SA_WF_EXAM_INST B
  224.                          WHERE A.SUBJECT_INST_ID = B.SUBJECT_INST_ID
  225.                            AND A.PROC_INST_ID = B.PROC_INST_ID
  226.                            AND B.COMPLETE_FLAG = 0)
  227.                  GROUP BY ACT_INST_ID, SUSPEND_FLAG) E
  228.          WHERE LI.WI_WORKFORM_TYPE = FTM.WORKFORM_TYPE(+)
  229.            AND LI.ACTIVITY_INS_ID = E.ACT_INST_ID(+)
  230.            ) T
  231.  WHERE NOT EXISTS (SELECT 1
  232.           FROM EPSA_SN.SA_WF_WORKITEM_EXCLUDED_USER US
  233.          WHERE T.WORKITEM_INS_ID = US.WORKITEM_ID
  234.            AND US.USER_ID = '153812');

本次最佳化採用在查詢庫,避免快取對最佳化效果的影響,查詢庫硬體裝置,效能較差,由於查詢庫和生產庫,資料庫結構及資料量一致,執行時間請比對分析,查詢庫該語句執行時間:10分鐘14秒,合計:614秒。

 

點選(此處)摺疊或開啟

  1. Plan hash value: 2391298305
  2.                                                                                                                                               
  3. ----------------------------------------------------------------------------------------------------------------------------------------------
  4.                                                                                                                                               
  5. | Id | Operation | Name | Starts | E-Rows | A-Rows | A-Time | Buffers | Reads |
  6. | 1 | NESTED LOOPS ANTI | | 1 | 17 | 307 |00:10:14.08 | 338K| 102K|
  7. |* 2 | HASH JOIN OUTER | | 1 | 17 | 438 |00:10:00.63 | 333K| 99548 |
  8. |* 3 | HASH JOIN RIGHT OUTER | | 1 | 17 | 438 |00:10:00.07 | 333K| 99040 |
  9. | 4 | INDEX FULL SCAN | PK_SA_WF_WORKFORM_TYPE_MAP | 1 | 155 | 155 |00:00:00.01 | 1 | 1 |
  10. | 5 | VIEW | | 1 | 17 | 438 |00:10:00.06 | 333K| 99039 |
  11. | 6 | UNION-ALL | | 1 | | 438 |00:10:00.06 | 333K| 99039 |
  12. | 7 | NESTED LOOPS OUTER | | 1 | 14 | 437 |00:08:25.77 | 146K| 84745 |
  13. | 8 | NESTED LOOPS OUTER | | 1 | 14 | 437 |00:08:25.67 | 145K| 84730 |
  14. | 9 | NESTED LOOPS OUTER | | 1 | 14 | 437 |00:08:25.52 | 144K| 84711 |
  15. |* 10 | HASH JOIN RIGHT OUTER | | 1 | 14 | 437 |00:08:24.91 | 143K| 84637 |
  16. |* 11 | TABLE ACCESS FULL | RT_OVERTIME_DEAL | 1 | 282 | 282 |00:00:00.01 | 6 | 5 |
  17. | 12 | NESTED LOOPS OUTER | | 1 | 14 | 437 |00:08:24.89 | 143K| 84632 |
  18. | 13 | NESTED LOOPS | | 1 | 14 | 437 |00:08:24.88 | 143K| 84631 |
  19. | 14 | VIEW | | 1 | 1348 | 26101 |00:07:32.20 | 83627 | 74518 |
  20. | 15 | UNION-ALL | | 1 | | 26101 |00:07:32.17 | 83627 | 74518 |
  21. |* 16 | TABLE ACCESS BY INDEX ROWID | RT_WORKITEMINST | 1 | 10 | 2 |00:00:55.51 | 8328 | 8119 |
  22. |* 17 | INDEX RANGE SCAN | IDX_RT_WORKITEM_USER_DEPART | 1 | 1673 | 9402 |00:00:00.59 | 94 | 92 |
  23. |* 18 | TABLE ACCESS BY INDEX ROWID | RT_WORKITEMINST | 1 | 10 | 26099 |00:06:36.60 | 75299 | 66399 |
  24. | 19 | NESTED LOOPS | | 1 | 1338 | 89575 |00:00:04.55 | 4301 | 785 |
  25. |* 20 | INDEX RANGE SCAN | PK_SA_BROLE_USER | 1 | 131 | 286 |00:00:00.03 | 5 | 5 |
  26. |* 21 | INDEX RANGE SCAN | IDX_RT_WORKITEM_USER_DEPART | 286 | 1673 | 89288 |00:00:04.39 | 4296 | 780 |
  27. |* 22 | TABLE ACCESS BY INDEX ROWID | SA_WORKFORM_INST | 26101 | 1 | 437 |00:00:52.66 | 60358 | 10113 |
  28. |* 23 | INDEX UNIQUE SCAN | IDX_WORKFORM_PROCINST_ID | 26101 | 1 | 6965 |00:00:30.76 | 53393 | 5009 |
  29. | 24 | TABLE ACCESS BY INDEX ROWID | SA_WF_BUSINESS_EXT | 437 | 1 | 0 |00:00:00.01 | 2 | 1 |
  30. |* 25 | INDEX UNIQUE SCAN | PK_SA_WF_BUSINESS_EXT | 437 | 1 | 0 |00:00:00.01 | 2 | 1 |
  31. | 26 | TABLE ACCESS BY INDEX ROWID | SA_USER | 437 | 1 | 437 |00:00:00.61 | 919 | 74 |
  32. |* 27 | INDEX UNIQUE SCAN | PK_SA_USER | 437 | 1 | 437 |00:00:00.22 | 439 | 23 |
  33. | 28 | TABLE ACCESS BY INDEX ROWID | SA_DEPT | 437 | 1 | 437 |00:00:00.15 | 876 | 19 |
  34. |* 29 | INDEX UNIQUE SCAN | PK_SA_DEPT | 437 | 1 | 437 |00:00:00.03 | 439 | 7 |
  35. | 30 | TABLE ACCESS BY INDEX ROWID | SA_ORG | 437 | 1 | 437 |00:00:00.10 | 876 | 15 |
  36. |* 31 | INDEX UNIQUE SCAN | PK_SA_ORG | 437 | 1 | 437 |00:00:00.04 | 439 | 6 |
  37. | 32 | NESTED LOOPS OUTER | | 1 | 3 | 1 |00:01:34.28 | 186K| 14294 |
  38. | 33 | NESTED LOOPS OUTER | | 1 | 3 | 1 |00:01:34.27 | 186K| 14292 |
  39. | 34 | NESTED LOOPS OUTER | | 1 | 3 | 1 |00:01:34.27 | 186K| 14292 |
  40. | 35 | NESTED LOOPS OUTER | | 1 | 3 | 1 |00:01:34.27 | 186K| 14292 |
  41. | 36 | NESTED LOOPS OUTER | | 1 | 3 | 1 |00:01:34.27 | 186K| 14292 |
  42. | 37 | NESTED LOOPS ANTI | | 1 | 3 | 1 |00:01:34.27 | 186K| 14292 |
  43. | 38 | NESTED LOOPS | | 1 | 3 | 1 |00:01:34.27 | 186K| 14292 |
  44. | 39 | NESTED LOOPS | | 1 | 321 | 484 |00:01:33.66 | 185K| 14180 |
  45. | 40 | VIEW | | 1 | 1348 | 26101 |00:00:00.97 | 80643 | 0 |
  46. | 41 | UNION-ALL | | 1 | | 26101 |00:00:00.95 | 80643 | 0 |
  47. |* 42 | TABLE ACCESS BY INDEX ROWID| RT_WORKITEMINST | 1 | 10 | 2 |00:00:00.08 | 8328 | 0 |
  48. |* 43 | INDEX RANGE SCAN | IDX_RT_WORKITEM_USER_DEPART | 1 | 1673 | 9402 |00:00:00.01 | 94 | 0 |
  49. |* 44 | TABLE ACCESS BY INDEX ROWID| RT_WORKITEMINST | 1 | 10 | 26099 |00:00:00.81 | 72315 | 0 |
  50. | 45 | NESTED LOOPS | | 1 | 1338 | 89575 |00:00:00.15 | 1665 | 0 |
  51. |* 46 | INDEX RANGE SCAN | PK_SA_BROLE_USER | 1 | 131 | 286 |00:00:00.01 | 5 | 0 |
  52. |* 47 | INDEX RANGE SCAN | IDX_RT_WORKITEM_USER_DEPART | 286 | 1673 | 89288 |00:00:00.03 | 1660 | 0 |
  53. |* 48 | TABLE ACCESS BY INDEX ROWID | RT_PROCESSINSTANCE | 26101 | 1 | 484 |00:01:32.66 | 104K| 14180 |
  54. |* 49 | INDEX RANGE SCAN | IDX20130719025 | 26101 | 1 | 26086 |00:00:41.13 | 78524 | 5630 |
  55. |* 50 | TABLE ACCESS BY INDEX ROWID | SA_WORKFORM_INST | 484 | 1 | 1 |00:00:00.61 | 1124 | 112 |
  56. |* 51 | INDEX UNIQUE SCAN | IDX_WORKFORM_PROCINST_ID | 484 | 1 | 154 |00:00:00.05 | 970 | 8 |
  57. |* 52 | INDEX UNIQUE SCAN | IDX_WORKFORM_PROCINST_ID | 1 | 1 | 0 |00:00:00.01 | 3 | 0 |
  58. | 53 | TABLE ACCESS BY INDEX ROWID | SA_USER | 1 | 1 | 1 |00:00:00.01 | 4 | 0 |
  59. |* 54 | INDEX UNIQUE SCAN | PK_SA_USER | 1 | 1 | 1 |00:00:00.01 | 2 | 0 |
  60. | 55 | TABLE ACCESS BY INDEX ROWID | SA_DEPT | 1 | 1 | 1 |00:00:00.01 | 3 | 0 |
  61. |* 56 | INDEX UNIQUE SCAN | PK_SA_DEPT | 1 | 1 | 1 |00:00:00.01 | 2 | 0 |
  62. | 57 | TABLE ACCESS BY INDEX ROWID | SA_WF_BUSINESS_EXT | 1 | 1 | 0 |00:00:00.01 | 1 | 0 |
  63. |* 58 | INDEX UNIQUE SCAN | PK_SA_WF_BUSINESS_EXT | 1 | 1 | 0 |00:00:00.01 | 1 | 0 |
  64. | 59 | TABLE ACCESS BY INDEX ROWID | SA_ORG | 1 | 1 | 1 |00:00:00.01 | 3 | 0 |
  65. |* 60 | INDEX UNIQUE SCAN | PK_SA_ORG | 1 | 1 | 1 |00:00:00.01 | 2 | 0 |
  66. | 61 | TABLE ACCESS BY INDEX ROWID | RT_OVERTIME_DEAL | 1 | 1 | 0 |00:00:00.01 | 2 | 2 |
  67. |* 62 | INDEX UNIQUE SCAN | PK_RT_OVERTIME_DEAL | 1 | 1 | 0 |00:00:00.01 | 2 | 2 |
  68. | 63 | VIEW | | 1 | 16536 | 597 |00:00:00.55 | 519 | 508 |
  69. | 64 | HASH GROUP BY | | 1 | 16536 | 597 |00:00:00.55 | 519 | 508 |
  70. |* 65 | HASH JOIN | | 1 | 16536 | 597 |00:00:00.55 | 519 | 508 |
  71. |* 66 | TABLE ACCESS FULL | SA_WF_EXAM_INST | 1 | 5024 | 238 |00:00:00.19 | 170 | 167 |
  72. | 67 | INDEX FAST FULL SCAN | PK_EXAM_ACT_INST | 1 | 32739 | 32739 |00:00:00.33 | 349 | 341 |
  73. |* 68 | TABLE ACCESS BY INDEX ROWID | SA_WF_WORKITEM_EXCLUDED_USER | 438 | 1 | 131 |00:00:13.44 | 4737 | 3440 |
  74. |* 69 | INDEX RANGE SCAN | IDX20130720140 | 438 | 106 | 136K|00:00:05.75 | 2509 | 1389 |

3 訪問路徑最佳化

EPSA_SN.SA_WORKFORM_INST,索引訪問次數:26101,回表次數:26101,合計:52202次IO,全表掃描訪問:4064次IO,建議修改為全表掃描。

RT_PROCESSINSTANCE:同上分析,該也建議全表掃描

圖1 表EPSA_SN.SA_WORKFORM_INST索引掃描

2表EPSA_SN.SA_WORKFORM_INST,全表掃描訪問:4064次IO,表RT_PROCESSINSTANCE全表掃描訪問次數:18784

最佳化測試:

alter system flush shared_pool;

alter system flush buffer_cache;--消除快取影響

--修改hint如下,


點選(此處)摺疊或開啟

  1. SELECT *
  2.   FROM (
  3.   SELECT LI.*,
  4.                CASE
  5.                  WHEN LI.OVERDUED_NE = 1 OR LI.OVERDUED_NE = 3 THEN
  6.                   1
  7.                  WHEN LI.OVERDUED_NE = 0 OR LI.OVERDUED_NE = 2 THEN
  8.                   CASE
  9.                     WHEN E.SUSPEND_FLAG = 0 THEN
  10.                      CASE
  11.                        WHEN SYSTIMESTAMP >= E.TARGET_OVERDUE_MINTIME THEN
  12.                         1
  13.                        ELSE
  14.                         0
  15.                      END
  16.                     WHEN E.SUSPEND_FLAG = 1 THEN
  17.                      CASE
  18.                        WHEN E.SUSPEND_TIME >= E.TARGET_OVERDUE_MINTIME THEN
  19.                         1
  20.                        ELSE
  21.                         0
  22.                      END
  23.                     ELSE
  24.                      0
  25.                   END
  26.                  ELSE
  27.                   0
  28.                END OVERDUED,
  29.                CASE
  30.                  WHEN E.TARGET_OVERDUE_MINTIME IS NULL THEN
  31.                   LI.TARGET_TIME_NE
  32.                  WHEN LI.TARGET_TIME_NE IS NULL THEN
  33.                   E.TARGET_OVERDUE_MINTIME
  34.                  WHEN E.TARGET_OVERDUE_MINTIME <= LI.TARGET_TIME_NE THEN
  35.                   E.TARGET_OVERDUE_MINTIME
  36.                  ELSE
  37.                   LI.TARGET_TIME_NE
  38.                END TARGET_TIME,
  39.                FTM.WORKFORM_TYPE_KIND
  40.           FROM (
  41.           SELECT /*+full(F)*/
  42.                  WF.PROC_INSTANCE_ID,
  43.                  WF.ACTIVITY_INS_ID,
  44.                  WF.WORKITEM_INS_ID,
  45.                  WF.NAME,
  46.                  WF.CURRENT_STATE,
  47.                  WF.COMPLETE_TIME,
  48.                  WF.CREATE_TIME,
  49.                  WF.LIMIT_TIME,
  50.                  WF.APP_URL,
  51.                  WF.USER_NAME,
  52.                  WF.USER_ID,
  53.                  WF.USER_ENTITY_TYPE,
  54.                  WF.USER_ENTITY_NAME,
  55.                  WF.USER_ENTITY_ID,
  56.                  WF.PARTICIPANT_TYPE,
  57.                  WF.SEND_TYPE,
  58.                  WF.OVERDUED AS OVERDUED_NE,
  59.                  WF.EXT_PROP,
  60.                  WF.FLOW_DIRECTION,
  61.                  WF.BUSINESSKEY,
  62.                  WF.DEPART_ID,
  63.                  F.INSTANCE_ID AS WI_INSTANCE_ID,
  64.                  F.INSTANCE_NAME AS WI_INSTANCE_NAME,
  65.                  F.WORKFORM_TYPE AS WI_WORKFORM_TYPE,
  66.                  F.BUILDER AS WI_BUILDER,
  67.                  F.START_TIME AS WI_CREATE_TIME,
  68.                  F.INSTANCE_STATUS AS WI_INSTANCE_STATUS,
  69.                  F.BUSINESS AS WI_BUSINESS,
  70.                  F.KEYDATA_ID AS WI_KEYDATA_ID,
  71.                  F.IS_FLOW AS WI_IS_FLOW,
  72.                  F.ATTR1 AS WI_ATTR1,
  73.                  F.DEPT_ID AS WI_DEPT_ID,
  74.                  '' AS WT_DEPT_ID,
  75.                  WF.CURRENT_STATE AS WT_WORKTASK_STATUS,
  76.                  NULL AS WT_TARGET_TIME,
  77.                  '' AS WT_LINK_URL,
  78.                  '' AS WT_LINK_PARAM,
  79.                  '' AS WT_IS_BATCH,
  80.                  U.REAL_NAME AS WI_BUILDER_REALNAME,
  81.                  NULL AS HOWLONG_WILL_OVERDUE,
  82.                  NULL AS HOWLONG_OVERDUED,
  83.                  '' AS ACTIVITY_TMP_ID,
  84.                  O.TIME_OUT_TIME AS TARGET_TIME_NE,
  85.                  B.APPROVAL_STATUS AS BE_APPROVAL_STATUS,
  86.                  ORG.ORG_NO,
  87.                  ORG.ORG_NAME,
  88.                  '' AS VIEW_FLAGS
  89.                   FROM EPSA_SN.SA_WORKFORM_INST F,
  90.                        (SELECT W.*
  91.                           FROM EPSA_SN.RT_WORKITEMINST W
  92.                          WHERE (W.CURRENT_STATE = 1 OR W.CURRENT_STATE = 2 OR
  93.                                W.CURRENT_STATE = 3)
  94.                            AND W.USER_ID = '153812'
  95.                            AND W.PARTICIPANT_TYPE = 0
  96.                         UNION ALL
  97.                         SELECT W.*
  98.                           FROM EPSA_SN.RT_WORKITEMINST W, EPSA_SN.SA_BROLE_USER R
  99.                          WHERE (W.CURRENT_STATE = 1 OR W.CURRENT_STATE = 2 OR
  100.                                W.CURRENT_STATE = 3)
  101.                            AND W.USER_ID = R.ROLE_ID
  102.                            AND R.USER_ID = '153812'
  103.                            AND W.PARTICIPANT_TYPE = 1) WF,
  104.                         EPSA_SN.SA_USER U,
  105.                        (SELECT * FROM EPSA_SN.RT_OVERTIME_DEAL WHERE TIMER_TYPE = 1) O,
  106.                         EPSA_SN.SA_WF_BUSINESS_EXT B,
  107.                         EPSA_SN.SA_DEPT D,
  108.                         EPSA_SN.SA_ORG ORG
  109.                  WHERE F.PROCINST_ID = WF.PROC_INSTANCE_ID --F.PROCINST_ID
  110.                    AND WF.WORKITEM_INS_ID = O.INSTANCE_ID(+)
  111.                    AND F.BUILDER = U.USER_ID(+) --F.BUILDER
  112.                    AND U.DEPT_ID = D.DEPT_ID(+)
  113.                    AND D.ORG_NO = ORG.ORG_NO(+)
  114.                    AND WF.WORKITEM_INS_ID = B.WORKITEM_ID(+)
  115.                    AND (WF.PARTICIPANT_TYPE = 0 OR
  116.                        (WF.PARTICIPANT_TYPE = 1 AND
  117.                        ((WF.DEPART_ID IS NOT NULL AND
  118.                        ((WF.DEPART_ID LIKE '*61102|201181|6140143000|6140143009%') OR
  119.                        ('61102|201181|6140143000|6140143009' LIKE (WF.DEPART_ID || '%')) OR
  120.                        ('$61102|201181|6140143000|6140143009' = WF.DEPART_ID))) OR
  121.                        ((WF.DEPART_ID IS NULL OR Wf.DEPART_ID = '') AND
  122.                        ((F.DEPT_ID LIKE '*61102|201181|6140143000|6140143009%') OR --F.DEPT_ID
  123.                        ('61102|201181|6140143000|6140143009' LIKE (F.DEPT_ID || '%')) OR ('$61102|201181|6140143000|6140143009' = F.DEPT_ID))))))
  124.                 UNION ALL
  125.                 SELECT /*+full(P)*/
  126.                  WF.PROC_INSTANCE_ID,
  127.                  WF.ACTIVITY_INS_ID,
  128.                  WF.WORKITEM_INS_ID,
  129.                  WF.NAME,
  130.                  WF.CURRENT_STATE,
  131.                  WF.COMPLETE_TIME,
  132.                  WF.CREATE_TIME,
  133.                  WF.LIMIT_TIME,
  134.                  WF.APP_URL,
  135.                  WF.USER_NAME,
  136.                  WF.USER_ID,
  137.                  WF.USER_ENTITY_TYPE,
  138.                  WF.USER_ENTITY_NAME,
  139.                  WF.USER_ENTITY_ID,
  140.                  WF.PARTICIPANT_TYPE,
  141.                  WF.SEND_TYPE,
  142.                  WF.OVERDUED AS OVERDUED_NE,
  143.                  WF.EXT_PROP,
  144.                  WF.FLOW_DIRECTION,
  145.                  WF.BUSINESSKEY,
  146.                  WF.DEPART_ID,
  147.                  F.INSTANCE_ID AS WI_INSTANCE_ID,
  148.                  F.INSTANCE_NAME AS WI_INSTANCE_NAME,
  149.                  F.WORKFORM_TYPE AS WI_WORKFORM_TYPE,
  150.                  F.BUILDER AS WI_BUILDER,
  151.                  F.START_TIME AS WI_CREATE_TIME,
  152.                  F.INSTANCE_STATUS AS WI_INSTANCE_STATUS,
  153.                  F.BUSINESS AS WI_BUSINESS,
  154.                  F.KEYDATA_ID AS WI_KEYDATA_ID,
  155.                  F.IS_FLOW AS WI_IS_FLOW,
  156.                  F.ATTR1 AS WI_ATTR1,
  157.                  F.DEPT_ID AS WI_DEPT_ID,
  158.                  '' AS WT_DEPT_ID,
  159.                  WF.CURRENT_STATE AS WT_WORKTASK_STATUS,
  160.                  NULL AS WT_TARGET_TIME,
  161.                  '' AS WT_LINK_URL,
  162.                  '' AS WT_LINK_PARAM,
  163.                  '' AS WT_IS_BATCH,
  164.                  U.REAL_NAME AS WI_BUILDER_REALNAME,
  165.                  NULL AS HOWLONG_WILL_OVERDUE,
  166.                  NULL AS HOWLONG_OVERDUED,
  167.                  '' AS ACTIVITY_TMP_ID,
  168.                  O.TIME_OUT_TIME AS TARGET_TIME_NE,
  169.                  B.APPROVAL_STATUS AS BE_APPROVAL_STATUS,
  170.                  ORG.ORG_NO,
  171.                  ORG.ORG_NAME,
  172.                  '' AS VIEW_FLAGS
  173.                   FROM EPSA_SN.SA_WORKFORM_INST F,
  174.                        (SELECT W.*
  175.                           FROM EPSA_SN.RT_WORKITEMINST W
  176.                          WHERE (W.CURRENT_STATE = 1 OR W.CURRENT_STATE = 2 OR
  177.                                W.CURRENT_STATE = 3)
  178.                            AND W.USER_ID = '153812'
  179.                            AND W.PARTICIPANT_TYPE = 0
  180.                         UNION ALL
  181.                         SELECT W.*
  182.                           FROM EPSA_SN.RT_WORKITEMINST W, EPSA_SN.SA_BROLE_USER R
  183.                          WHERE (W.CURRENT_STATE = 1 OR W.CURRENT_STATE = 2 OR
  184.                                W.CURRENT_STATE = 3)
  185.                            AND W.USER_ID = R.ROLE_ID
  186.                            AND R.USER_ID = '153812'
  187.                            AND W.PARTICIPANT_TYPE = 1) WF,
  188.                         EPSA_SN.SA_USER U,
  189.                         EPSA_SN.RT_PROCESSINSTANCE P,
  190.                        (SELECT * FROM EPSA_SN.RT_OVERTIME_DEAL WHERE TIMER_TYPE = 1) O,
  191.                         EPSA_SN.SA_WF_BUSINESS_EXT B,
  192.                         EPSA_SN.SA_DEPT D,
  193.                         EPSA_SN.SA_ORG ORG
  194.                  WHERE WF.PROC_INSTANCE_ID = P.PROC_INSTANCE_ID
  195.                    AND P.PARENT_PROCINC_ID IS NOT NULL
  196.                    AND F.PROCINST_ID = P.PARENT_PROCINC_ID
  197.                    AND F.BUILDER = U.USER_ID(+)
  198.                    AND U.DEPT_ID = D.DEPT_ID(+)
  199.                    AND D.ORG_NO = ORG.ORG_NO(+)
  200.                    AND WF.WORKITEM_INS_ID = O.INSTANCE_ID(+)
  201.                    AND WF.WORKITEM_INS_ID = B.WORKITEM_ID(+)
  202.                    AND (WF.PARTICIPANT_TYPE = 0 OR
  203.                        (WF.PARTICIPANT_TYPE = 1 AND
  204.                        ((WF.DEPART_ID IS NOT NULL AND
  205.                        ((WF.DEPART_ID LIKE '*61102|201181|6140143000|6140143009%') OR
  206.                        ('61102|201181|6140143000|6140143009' LIKE (WF.DEPART_ID || '%')) OR
  207.                        ('$61102|201181|6140143000|6140143009' = WF.DEPART_ID))) OR
  208.                        ((WF.DEPART_ID IS NULL OR Wf.DEPART_ID = '') AND
  209.                        ((F.DEPT_ID LIKE '*61102|201181|6140143000|6140143009%') OR
  210.                        ('61102|201181|6140143000|6140143009' LIKE (F.DEPT_ID || '%')) OR
  211.                        ('$61102|201181|6140143000|6140143009' = F.DEPT_ID))))))
  212.                    AND NOT EXISTS
  213.                  (SELECT 1
  214.                           FROM EPSA_SN.SA_WORKFORM_INST RF
  215.                          WHERE WF.PROC_INSTANCE_ID = RF.PROCINST_ID)
  216.                          ) LI,
  217.                 EPSA_SN.SA_WF_WORKFORM_TYPE_MAP FTM,
  218.                (SELECT ACT_INST_ID,
  219.                        SUSPEND_FLAG,
  220.                        MIN(TARGET_OVERDUE_MINTIME) AS TARGET_OVERDUE_MINTIME,
  221.                        MIN(SUSPEND_TIME) AS SUSPEND_TIME
  222.                   FROM (SELECT A.ACT_INST_ID, B.*
  223.                           FROM EPSA_SN.SA_WF_EXAM_ACT_INST A, EPSA_SN.SA_WF_EXAM_INST B
  224.                          WHERE A.SUBJECT_INST_ID = B.SUBJECT_INST_ID
  225.                            AND A.PROC_INST_ID = B.PROC_INST_ID
  226.                            AND B.COMPLETE_FLAG = 0)
  227.                  GROUP BY ACT_INST_ID, SUSPEND_FLAG) E
  228.          WHERE LI.WI_WORKFORM_TYPE = FTM.WORKFORM_TYPE(+)
  229.            AND LI.ACTIVITY_INS_ID = E.ACT_INST_ID(+)
  230.            ) T
  231.  WHERE NOT EXISTS (SELECT 1
  232.           FROM EPSA_SN.SA_WF_WORKITEM_EXCLUDED_USER US
  233.          WHERE T.WORKITEM_INS_ID = US.WORKITEM_ID
  234.            AND US.USER_ID = '153812');




4.   小結

透過訪問路徑最佳化:  最佳化前執行時間:614秒,最佳化後:83秒。



來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/31442014/viewspace-2144865/,如需轉載,請註明出處,否則將追究法律責任。

相關文章