如何调整以下查询

时间:2019-04-17 11:40:34

标签: performance query-tuning

我正在尝试调整下面的代码,但无法获得肯定的结果。

我尝试了一些索引和提示。下面是需要很多时间的查询。我需要调整此查询。 我还粘贴了以下查询的解释计划。有人可以让我知道可以做些什么来调整它。

WITH slot_and_sub_slot AS
  (SELECT DISTINCT mv.sne,
    mv.parent_iv_sysid,
    mv.isu,
    mv.parent_card_log_pos,
    mv.parent_card_dxc_pos,
    mv.child_log_pos,
    mv.child_dxc_pos,
    mv1.sne_id EQPT,
    mv1.locality_name,
    mv1.trs_1141_code,
    mv1.device_manufacturer
    ||' / '
    || mv1.device_type
    ||' / '
    || mv1.device_model
    ||' / '
    || mv1.device_version
    ||' / '
    || mv1.device_usage Device
  FROM BUILD_CARD_HIERARCHY_MV_ES MV,
    linechart_freeslots_mv mv1,
    potential_card_versions pcv,
    inventory_versions iv_p,
    shelf_instances si,
    potential_iv_versions piv
  ,look_up_values luv
  WHERE mv.sne                = mv1.sne_id
  AND mv1.LOC_1141_CODE       = 'AA'
  AND pcv.plp_isu_sysid       = mv.isu
  AND mv.CHILD_IV_SYSID       = PCV.IV_SYSID
  AND pcv.plp_log_pos_type    = mv.child_log_pos
  AND pcv.plp_dxc_pos_no      = '0'
  AND pcv.iv_sysid            = piv.card_iv_sysid
  AND pcv.plp_log_pos_type    = piv.card_log_pos_type
  AND iv_p.sysid              = si.iv_sysid
  AND si.iv_sysid             = piv.shelf_iv_sysid
  AND si.lps_sne_id           = mv.sne
  AND si.lps_plp_log_pos_type = piv.shelf_log_pos_type
  AND iv_p.component_type     = 'R'
   AND '' || mv.isu = luv.look_up_value
                AND luv.table_name = 'LOCATION_SUMMARY'
                AND luv.column_name = 'MODEL'
                and mv.sne=16831
  ),
  child_card AS
  ( SELECT DISTINCT sss.sne lp_sne_id,
    sss.isu lp_plp_isu_sysid,
    sss.child_log_pos lp_plp_log_pos_type,
    sss.child_dxc_pos lp_plp_dxc_pos_no,
    sss.locality_name,
    sss.trs_1141_code,
    sss.Device
  FROM slot_and_sub_slot sss,
    inventory_versions iv1
  WHERE iv1.sysid                      = sss.parent_iv_sysid
    START WITH sss.parent_card_log_pos = sss.parent_card_log_pos
    CONNECT BY PRIOR sss.child_log_pos = sss.parent_card_log_pos
  AND PRIOR sss.child_dxc_pos          = sss.parent_card_dxc_pos
  )
SELECT COUNT (1) count_slots
FROM
  (SELECT DISTINCT child_card.lp_plp_log_pos_type,
    child_card.lp_plp_dxc_pos_no,
    child_card.lp_sne_id EQPT,
    child_card.locality_name,
    child_card.trs_1141_code
  FROM child_card
  WHERE NOT EXISTS
    (SELECT 1
    FROM CARDS car
    WHERE car.lps_sne_id         = child_card.lp_sne_id
    AND car.lps_plp_log_pos_type = child_card.lp_plp_log_pos_type
    )
  UNION
  SELECT DISTINCT lgp.plp_log_pos_type lp_plp_log_pos_type,
    LGP.PLP_DXC_POS_NO lp_plp_dxc_pos_no,
    sne1.sne_id eqpt,
    l.name locality_name,
    sne1.TA_CODE_1141 trs_1141_code
  FROM SDH_NETWORK_ELEMENTS sne1,
    LOGICAL_POSITIONS lgp,
    INVENTORY_SNE_USAGES isu1,
    LOCALITIES l,
    look_up_values luv,
    parties p,
    potential_card_versions pcv,
    inventory_versions iv_p,
    shelf_instances si,
    potential_iv_versions piv
  WHERE l.code_1141      = sne1.loc_code_1141
  AND lgp.sne_id         = sne1.sne_id
  AND lgp.shelf_log_pos  = 'N'
  AND isu1.sysid         = sne1.isu_sysid
  AND sne1.loc_code_1141 = 'AA'
  AND isu1.iv_par_id     = p.par_id
  AND ''
    || isu1.sysid             = luv.look_up_value
  AND luv.table_name          = 'LOCATION_SUMMARY'
  AND luv.column_name         = 'MODEL'
  AND pcv.plp_isu_sysid       = isu1.sysid
  AND pcv.plp_log_pos_type    = lgp.plp_log_pos_type
  AND pcv.plp_dxc_pos_no      = '0'
  AND pcv.iv_sysid            = piv.card_iv_sysid
  AND pcv.plp_log_pos_type    = piv.card_log_pos_type
  AND iv_p.sysid              = si.iv_sysid
  AND si.iv_sysid             = piv.shelf_iv_sysid
  AND si.lps_sne_id           = lgp.sne_id
  AND si.lps_plp_log_pos_type = piv.shelf_log_pos_type
  AND iv_p.component_type     = 'R'
  AND NOT EXISTS
    (SELECT 1
    FROM CARDS car
    WHERE car.lps_sne_id         = lgp.sne_id
    AND car.lps_plp_log_pos_type = lgp.plp_log_pos_type
    )
  );


Plan hash value: 1744937147

--------------------------------------------------------------------------------------------------------------------------
| Id  | Operation                                 | Name                         | Rows  | Bytes | Cost (%CPU)| Time     |
--------------------------------------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT                          |                              |     1 |       |    86   (5)| 00:00:02 |
|   1 |  TEMP TABLE TRANSFORMATION                |                              |       |       |            |          |
|   2 |   LOAD AS SELECT                          |                              |       |       |            |          |
|   3 |    HASH UNIQUE                            |                              |     1 |   477 |    18   (6)| 00:00:01 |
|   4 |     NESTED LOOPS                          |                              |     1 |   477 |    17   (0)| 00:00:01 |
|   5 |      NESTED LOOPS                         |                              |     1 |   470 |    16   (0)| 00:00:01 |
|   6 |       NESTED LOOPS                        |                              |     1 |   442 |    16   (0)| 00:00:01 |
|   7 |        NESTED LOOPS                       |                              |     1 |   423 |    16   (0)| 00:00:01 |
|   8 |         NESTED LOOPS                      |                              |     1 |   378 |    16   (0)| 00:00:01 |
|   9 |          MERGE JOIN CARTESIAN             |                              |     1 |   119 |     2   (0)| 00:00:01 |
|* 10 |           INDEX RANGE SCAN                | SHI_SNE_POS_ISU_IV_UK        |     1 |    17 |     2   (0)| 00:00:01 |
|  11 |           BUFFER SORT                     |                              |     1 |   102 |     0   (0)| 00:00:01 |
|  12 |            MAT_VIEW ACCESS BY INDEX ROWID | BUILD_CARD_HIERARCHY_MV_ES   |     1 |   102 |     0   (0)| 00:00:01 |
|* 13 |             INDEX RANGE SCAN              | INDX_BCH_SNE                 |     1 |       |     0   (0)| 00:00:01 |
|  14 |          MAT_VIEW ACCESS BY INDEX ROWID   | LINECHART_FREESLOTS_MV       |    45 | 11655 |    16   (0)| 00:00:01 |
|  15 |           BITMAP CONVERSION TO ROWIDS     |                              |       |       |            |          |
|  16 |            BITMAP AND                     |                              |       |       |            |          |
|  17 |             BITMAP CONVERSION FROM ROWIDS |                              |       |       |            |          |
|* 18 |              INDEX RANGE SCAN             | INDX_LINECHART_FREESLOTS_SNE |   224 |       |     0   (0)| 00:00:01 |
|  19 |             BITMAP CONVERSION FROM ROWIDS |                              |       |       |            |          |
|* 20 |              INDEX RANGE SCAN             | INDX_LFM_LOC_1141_CODE       |   224 |       |     0   (0)| 00:00:01 |
|* 21 |         INDEX UNIQUE SCAN                 | LUV_PK                       |     1 |    45 |     0   (0)| 00:00:01 |
|* 22 |        INDEX UNIQUE SCAN                  | PCV_UK                       |     1 |    19 |     0   (0)| 00:00:01 |
|* 23 |       INDEX UNIQUE SCAN                   | PIV_UNIQUE                   |     1 |    28 |     0   (0)| 00:00:01 |
|* 24 |      TABLE ACCESS BY INDEX ROWID          | INVENTORY_VERSIONS           |     1 |     7 |     1   (0)| 00:00:01 |
|* 25 |       INDEX UNIQUE SCAN                   | IV_PK                        |     1 |       |     0   (0)| 00:00:01 |
|  26 |   SORT AGGREGATE                          |                              |     1 |       |            |          |
|  27 |    VIEW                                   |                              |     2 |       |    68   (5)| 00:00:01 |
|  28 |     SORT UNIQUE                           |                              |     2 |   358 |    68  (93)| 00:00:01 |
|  29 |      UNION-ALL                            |                              |       |       |            |          |
|* 30 |       FILTER                              |                              |       |       |            |          |
|  31 |        VIEW                               |                              |     1 |   173 |     3  (34)| 00:00:01 |
|  32 |         HASH UNIQUE                       |                              |     1 |   332 |     3  (34)| 00:00:01 |
|* 33 |          CONNECT BY WITH FILTERING        |                              |       |       |            |          |
|* 34 |           FILTER                          |                              |       |       |            |          |
|  35 |            COUNT                          |                              |       |       |            |          |
|  36 |             NESTED LOOPS                  |                              |     1 |   332 |     2   (0)| 00:00:01 |
|  37 |              VIEW                         |                              |     1 |   327 |     2   (0)| 00:00:01 |
|  38 |               TABLE ACCESS FULL           | SYS_TEMP_0FD9D6603_78A91C0C  |     1 |   340 |     2   (0)| 00:00:01 |
|* 39 |              INDEX UNIQUE SCAN            | IV_PK                        |     1 |     5 |     0   (0)| 00:00:01 |
|* 40 |           HASH JOIN                       |                              |       |       |            |          |
|  41 |            CONNECT BY PUMP                |                              |       |       |            |          |
|  42 |            COUNT                          |                              |       |       |            |          |
|  43 |             NESTED LOOPS                  |                              |     1 |   332 |     2   (0)| 00:00:01 |
|  44 |              VIEW                         |                              |     1 |   327 |     2   (0)| 00:00:01 |
|  45 |               TABLE ACCESS FULL           | SYS_TEMP_0FD9D6603_78A91C0C  |     1 |   340 |     2   (0)| 00:00:01 |
|* 46 |              INDEX UNIQUE SCAN            | IV_PK                        |     1 |     5 |     0   (0)| 00:00:01 |
|* 47 |        INDEX RANGE SCAN                   | CAR_PK                       |     1 |    13 |     3   (0)| 00:00:01 |
|  48 |       NESTED LOOPS                        |                              |     1 |   185 |    57   (0)| 00:00:01 |
|  49 |        NESTED LOOPS                       |                              |     1 |   178 |    56   (0)| 00:00:01 |
|  50 |         NESTED LOOPS                      |                              |     1 |   150 |    56   (0)| 00:00:01 |
|  51 |          NESTED LOOPS                     |                              |     1 |   131 |    55   (0)| 00:00:01 |
|  52 |           NESTED LOOPS                    |                              |     1 |   114 |    54   (0)| 00:00:01 |
|  53 |            NESTED LOOPS                   |                              |     1 |    96 |    52   (0)| 00:00:01 |
|  54 |             NESTED LOOPS                  |                              |     1 |    90 |    52   (0)| 00:00:01 |
|  55 |              MERGE JOIN CARTESIAN         |                              |     1 |    82 |    50   (0)| 00:00:01 |
|  56 |               NESTED LOOPS                |                              |     1 |    62 |     4   (0)| 00:00:01 |
|  57 |                TABLE ACCESS BY INDEX ROWID| LOCALITIES                   |     1 |    17 |     2   (0)| 00:00:01 |
|* 58 |                 INDEX UNIQUE SCAN         | LCL_PK                       |     1 |       |     1   (0)| 00:00:01 |
|* 59 |                INDEX RANGE SCAN           | LUV_PK                       |     1 |    45 |     2   (0)| 00:00:01 |
|  60 |               BUFFER SORT                 |                              |   190 |  3800 |    48   (0)| 00:00:01 |
|  61 |                TABLE ACCESS BY INDEX ROWID| SDH_NETWORK_ELEMENTS         |   190 |  3800 |    46   (0)| 00:00:01 |
|* 62 |                 INDEX RANGE SCAN          | SNE_LOC_CODE_1141_I          |   190 |       |     0   (0)| 00:00:01 |
|  63 |              TABLE ACCESS BY INDEX ROWID  | INVENTORY_SNE_USAGES         |     1 |     8 |     2   (0)| 00:00:01 |
|* 64 |               INDEX UNIQUE SCAN           | ISU_PK                       |     1 |       |     1   (0)| 00:00:01 |
|* 65 |             INDEX UNIQUE SCAN             | PAR_PK                       |     1 |     6 |     0   (0)| 00:00:01 |
|* 66 |            TABLE ACCESS BY INDEX ROWID    | LOGICAL_POSITIONS            |     4 |    72 |     2   (0)| 00:00:01 |
|* 67 |             INDEX RANGE SCAN              | LPS_PK                       |     7 |       |     1   (0)| 00:00:01 |
|* 68 |              INDEX RANGE SCAN             | CAR_PK                       |     1 |    13 |     3   (0)| 00:00:01 |
|* 69 |           INDEX RANGE SCAN                | SHI_SNE_POS_ISU_IV_UK        |     1 |    17 |     1   (0)| 00:00:01 |
|* 70 |          INDEX RANGE SCAN                 | PCV_UK                       |     1 |    19 |     1   (0)| 00:00:01 |
|* 71 |         INDEX UNIQUE SCAN                 | PIV_UNIQUE                   |     1 |    28 |     0   (0)| 00:00:01 |
|* 72 |        TABLE ACCESS BY INDEX ROWID        | INVENTORY_VERSIONS           |     1 |     7 |     1   (0)| 00:00:01 |
|* 73 |         INDEX UNIQUE SCAN                 | IV_PK                        |     1 |       |     0   (0)| 00:00:01 |
--------------------------------------------------------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

  10 - access("SI"."LPS_SNE_ID"=16831)
  13 - access("MV"."SNE"=16831)
  18 - access("MV1"."SNE_ID"=16831)
       filter("MV"."SNE"="MV1"."SNE_ID")
  20 - access("MV1"."LOC_1141_CODE"='AA')
  21 - access("LUV"."TABLE_NAME"='LOCATION_SUMMARY' AND "LUV"."COLUMN_NAME"='MODEL' AND 
              "LUV"."LOOK_UP_VALUE"=''||TO_CHAR("MV"."ISU"))
  22 - access("PCV"."PLP_ISU_SYSID"="MV"."ISU" AND "PCV"."PLP_LOG_POS_TYPE"="MV"."CHILD_LOG_POS" AND 
              "PCV"."PLP_DXC_POS_NO"=0 AND "MV"."CHILD_IV_SYSID"="PCV"."IV_SYSID")
  23 - access("SI"."IV_SYSID"="PIV"."SHELF_IV_SYSID" AND "SI"."LPS_PLP_LOG_POS_TYPE"="PIV"."SHELF_LOG_POS_TYPE" 
              AND "PCV"."IV_SYSID"="PIV"."CARD_IV_SYSID" AND "PCV"."PLP_LOG_POS_TYPE"="PIV"."CARD_LOG_POS_TYPE")
  24 - filter("IV_P"."COMPONENT_TYPE"='R')
  25 - access("IV_P"."SYSID"="SI"."IV_SYSID")
  30 - filter( NOT EXISTS (SELECT 0 FROM "CARDS" "CAR" WHERE "CAR"."LPS_PLP_LOG_POS_TYPE"=:B1 AND 
              "CAR"."LPS_SNE_ID"=:B2))
  33 - access("SSS"."PARENT_CARD_LOG_POS"=PRIOR "SSS"."CHILD_LOG_POS" AND "SSS"."PARENT_CARD_DXC_POS"=PRIOR 
              "SSS"."CHILD_DXC_POS")
  34 - filter("SSS"."PARENT_CARD_LOG_POS"="SSS"."PARENT_CARD_LOG_POS")
  39 - access("IV1"."SYSID"="SSS"."PARENT_IV_SYSID")
  40 - access("SSS"."PARENT_CARD_LOG_POS"=PRIOR "SSS"."CHILD_LOG_POS" AND "SSS"."PARENT_CARD_DXC_POS"=PRIOR 
              "SSS"."CHILD_DXC_POS")
  46 - access("IV1"."SYSID"="SSS"."PARENT_IV_SYSID")
  47 - access("CAR"."LPS_SNE_ID"=:B1 AND "CAR"."LPS_PLP_LOG_POS_TYPE"=:B2)
  58 - access("L"."CODE_1141"='AA')
  59 - access("LUV"."TABLE_NAME"='LOCATION_SUMMARY' AND "LUV"."COLUMN_NAME"='MODEL')
  62 - access("SNE1"."LOC_CODE_1141"='AA')
  64 - access("SNE1"."ISU_SYSID"="ISU1"."SYSID")
       filter("LUV"."LOOK_UP_VALUE"=''||TO_CHAR("ISU1"."SYSID"))
  65 - access("ISU1"."IV_PAR_ID"="P"."PAR_ID")
  66 - filter("LGP"."SHELF_LOG_POS"='N')
  67 - access("LGP"."SNE_ID"="SNE1"."SNE_ID")
       filter( NOT EXISTS (SELECT 0 FROM "CARDS" "CAR" WHERE "CAR"."LPS_PLP_LOG_POS_TYPE"=:B1 AND 
              "CAR"."LPS_SNE_ID"=:B2))
  68 - access("CAR"."LPS_SNE_ID"=:B1 AND "CAR"."LPS_PLP_LOG_POS_TYPE"=:B2)
  69 - access("SI"."LPS_SNE_ID"="LGP"."SNE_ID")
  70 - access("PCV"."PLP_ISU_SYSID"="ISU1"."SYSID" AND "PCV"."PLP_LOG_POS_TYPE"="LGP"."PLP_LOG_POS_TYPE" AND 
              "PCV"."PLP_DXC_POS_NO"=0)
  71 - access("SI"."IV_SYSID"="PIV"."SHELF_IV_SYSID" AND "SI"."LPS_PLP_LOG_POS_TYPE"="PIV"."SHELF_LOG_POS_TYPE" 
              AND "PCV"."IV_SYSID"="PIV"."CARD_IV_SYSID" AND "PCV"."PLP_LOG_POS_TYPE"="PIV"."CARD_LOG_POS_TYPE")
  72 - filter("IV_P"."COMPONENT_TYPE"='R')
  73 - access("IV_P"."SYSID"="SI"."IV_SYSID")

Note
-----
   - dynamic sampling used for this statement

0 个答案:

没有答案