sql查询执行时间太长

时间:2014-08-10 15:39:27

标签: sql performance oracle11gr2 sql-execution-plan query-tuning

我在查询时遇到问题。执行需要10个小时。

    WITH CONSUM AS (
    SELECT C.ID_MEASURER,C.ID_MEASURING_POINT,C.CONSUM_TYPE
    FROM GCGT_RE_CONSUM_H_E C
    WHERE C.DAY BETWEEN 20130201    AND 20130228    AND ACTIVE = 1 
    ),
    CORE AS (SELECT 
            SS.NISS,
            CO.ID_CONTRACT,
            CO.FROM_DATE AS FECHA_INI_CONTRATO,
            SS.ID_DISTRIBUTER,
            SS.ID_SECTOR_SUPPLY,
            MP.CUPS,
            M.ID_COMBINATION_USAGE_TYPE,
            MP.MP_FUNCTION,
            NVL (MP.FLAG_TELEMETRY, 0) AS TELEMEDIDO,
            NVL (CTYP.RELEVANCE, 0) AS RELEVANT_CONSUM_TYPE,
            MP.ID_MEASURER,
            CTYP.COD_USAGE_TYPE AS CONSUM_TYPE,
            0 AS VALUE_1,
            0 AS VALUE_2,  
            0 AS VALUE_3,
            0 AS VALUE_4,
            0 AS VALUE_5,
            0 AS VALUE_6,
            0 AS VALUE_7,
            0 AS VALUE_8,
            0 AS VALUE_9,
            0 AS VALUE_10,
            0 AS VALUE_11,
            0 AS VALUE_12,
            0 AS VALUE_13,
            0 AS VALUE_14,
            0 AS VALUE_15,
            0 AS VALUE_16,
            0 AS VALUE_17,
            0 AS VALUE_18,
            0 AS VALUE_19,
            0 AS VALUE_20,
            0 AS VALUE_21,
            0 AS VALUE_22,
            0 AS VALUE_23,
            0 AS VALUE_24,
            0 AS VALUE_25,
            '' AS SOURCE_1,
            '' AS SOURCE_2,  
            '' AS SOURCE_3,
            '' AS SOURCE_4,
            '' AS SOURCE_5,
            '' AS SOURCE_6,
            '' AS SOURCE_7,
            '' AS SOURCE_8,
            '' AS SOURCE_9,
            '' AS SOURCE_10,
            '' AS SOURCE_11,
            '' AS SOURCE_12,
            '' AS SOURCE_13,
            '' AS SOURCE_14,
            '' AS SOURCE_15,
            '' AS SOURCE_16,
            '' AS SOURCE_17,
            '' AS SOURCE_18,
            '' AS SOURCE_19,
            '' AS SOURCE_20,
            '' AS SOURCE_21,
            '' AS SOURCE_22,
            '' AS SOURCE_23,
            '' AS SOURCE_24,
            '' AS SOURCE_25,
            0 AS QUALITY_1,
            0 AS QUALITY_2,  
            0 AS QUALITY_3,
            0 AS QUALITY_4,
            0 AS QUALITY_5,
            0 AS QUALITY_6,
            0 AS QUALITY_7,
            0 AS QUALITY_8,
            0 AS QUALITY_9,
            0 AS QUALITY_10,
            0 AS QUALITY_11,
            0 AS QUALITY_12,
            0 AS QUALITY_13,
            0 AS QUALITY_14,
            0 AS QUALITY_15,
            0 AS QUALITY_16,
            0 AS QUALITY_17,
            0 AS QUALITY_18,
            0 AS QUALITY_19,
            0 AS QUALITY_20,
            0 AS QUALITY_21,
            0 AS QUALITY_22,
            0 AS QUALITY_23,
            0 AS QUALITY_24,
            0 AS QUALITY_25,
            20130228    AS DAY,
            TRUNC(20130228   ,-2) AS FIRST_DAY,
            TRUNC(20130228   ,-2) + 31 AS LAST_DAY,
            NVL (MTY.COD_USER, '') AS ORIGIN,
            SC.ID_CONTRACTED_SERVICE,
            0 AS BAJA,
            NVL(SC.IND_GUARANTOR, 0) AS GESTION_ATR,
            SC.NISC
            FROM GCGT_RE_MEASUREMENT_POINT MP
                    INNER JOIN GCCOM_SECTOR_SUPPLY SS ON MP.ID_SECTOR_SUPPLY = SS.ID_SECTOR_SUPPLY
                    INNER JOIN GCGT_ME_MEASURER M ON M.ID_MEASURER = MP.ID_MEASURER
                    INNER JOIN GCCOM_CONTRACTED_SERVICE SC ON SC.ID_SECTOR_SUPPLY = SS.ID_SECTOR_SUPPLY
                    INNER JOIN GCCOM_CONTRACT CO ON CO.ID_CONTRACT = SC.ID_CONTRACT
                    INNER JOIN GCGT_RE_MP_NATURE NAT ON NAT.ID_MP_NATURE = MP.ID_MP_NATURE
                    INNER JOIN GCGT_ME_MEA_CTYPE_HIST CTYP ON MP.ID_MEASURER = CTYP.ID_MEASURER 
                    INNER JOIN GCGT_RE_MODE_TYPE MTY ON MTY.COD_DEVELOP = NAT.COD_MODO
            WHERE 
                     1 = 1  
                    AND  1 = 1   
                    AND CTYP.FROM_DATE <= 20130228 
                    AND (CTYP.TO_DATE IS NULL OR CTYP.TO_DATE >= 20130201 )
                    AND CTYP.COD_USAGE_TYPE  NOT IN  ('AEH', 'R1H', 'AEQ', 'R1Q') 
                    AND MP.CUPS IS NOT NULL
                    AND SC.STATUS NOT IN ('ESTSC00004', 'ESTSC00005')
                    AND (SC.DROP_DATE is null or SC.DROP_DATE >= (TO_DATE(20130228   , 'YYYYMMDD')) )
                    /*and to_char(SC.FROM_DATE,'YYYYMM') <= SUBSTR (:P_INI_DATE, 1, 6) PMR */
                    AND SC.FROM_DATE <= LAST_DAY(TO_DATE(20130201   , 'YYYYMMDD'))
                    AND (CO.STATUS not in ('ESTCO00005','ESTCO00004') or (CO.END_DATE >= (TO_DATE (20130201   , 'YYYYMMDD')) and CO.STATUS = 'ESTCO00005' ) or (CO.DROP_DATE >= (TO_DATE (20130201   , 'YYYYMMDD')) and CO.STATUS = 'ESTCO00004'))
                    AND EXISTS
                              (SELECT UTM.ID_MEASURER
                                 FROM GCGT_ME_USAGE_TYPE_METER UTM
                                WHERE UTM.ID_MEASURER = MP.ID_MEASURER
                                  AND UTM.COD_USAGE_TYPE = CTYP.COD_USAGE_TYPE 
                                )                   
                    AND NOT EXISTS(
                        SELECT 1
                        FROM CONSUM C
                        WHERE C.ID_MEASURER = MP.ID_MEASURER
                        AND C.ID_MEASURING_POINT = MP.ID_MEASURING_POINT
                        AND C.CONSUM_TYPE = CTYP.COD_USAGE_TYPE))                     
    SELECT 
             CORE.NISS,
             CORE.ID_CONTRACT,
             '' AS MOT_BLOQ,
             CORE.FECHA_INI_CONTRATO,
             SUBSTR (CORE.DAY, 1, 6) AS PERIODO,
             EATT.FOREIGN_CONTRACT_NUMBER AS ATR_POLICY,
             COM.NAME_TYPE AS COD_DISTRIBUIDORA,
             --NVL (ROC.IND_CALC_ORDER, 0) AS IND_CALC_ORDER,
             (SELECT COUNT (1)
              FROM gccom_delivery_note dn
              WHERE dn.id_contracted_service = CORE.ID_CONTRACTED_SERVICE
                AND dn.delivery_note_status in ('BIDOCST001', 'BIDOCST003' )
                AND dn.ind_simulated = 0
                AND TO_CHAR (dn.forecast_billing_date, 'YYYYMM') >= SUBSTR (CORE.DAY, 1, 6)
                AND ROWNUM < 2)
             AS IND_CALC_ORDER,
             --NVL (ROC.IND_SENT_FACT, 0) AS IND_SENT_FACT,
             (SELECT COUNT (1)
              FROM gccom_delivery_note dn
              WHERE dn.id_contracted_service = CORE.ID_CONTRACTED_SERVICE
                AND dn.delivery_note_status = 'BIDOCST001'
                AND dn.ind_simulated = 0
                AND (dn.ind_not_billed = 0 or dn.ind_not_billed is null)
                AND TO_CHAR (dn.forecast_billing_date, 'YYYYMM') >= SUBSTR (CORE.DAY, 1, 6)
                AND ROWNUM < 2)
             AS IND_SENT_FACT,
             --NVL (ROC3.IND_SENT_FACT, 0) AS IND_SENT_FACT_ANT,
             (SELECT COUNT (1) 
              FROM gccom_delivery_note dn
              WHERE dn.id_contracted_service = CORE.ID_CONTRACTED_SERVICE
                  AND dn.delivery_note_status = 'BIDOCST001'
                  AND dn.ind_simulated = 0
                  AND (dn.ind_not_billed = 0 or dn.ind_not_billed is null)
                  AND TO_CHAR(dn.forecast_billing_date, 'YYYYMM') = (select TO_CHAR(max(dn.forecast_billing_date),'YYYYMM') 
                       FROM gccom_delivery_note dn 
                       where dn.id_contracted_service = CORE.ID_CONTRACTED_SERVICE 
                      and TO_CHAR(dn.forecast_billing_date, 'YYYYMM') < SUBSTR (CORE.DAY, 1, 6))
                  AND ROWNUM <2 )AS IND_SENT_FACT_ANT,
             CORE.CUPS,
             FAR.SHORT_NAME_TYPE AS TARIFA,
             CT.DESCRIPTION AS TIPO_CLIENTE,
             CORE.TELEMEDIDO,
             CORE.RELEVANT_CONSUM_TYPE,
             (
                SELECT COUNT (1)
                FROM GCGT_RE_READING_E RE
                WHERE RE.ID_MEASURER = CORE.ID_MEASURER 
                     AND  RE.DAY BETWEEN CORE.FIRST_DAY AND CORE.LAST_DAY
             ) AS CLOSED,
             (
                SELECT COUNT (1)
                FROM GCGT_RE_MEASUREMENT_POINT  RRMP
                WHERE RRMP.ID_SECTOR_SUPPLY = CORE.ID_SECTOR_SUPPLY
             ) AS MULTIPLEPM,
             NVL(
                (
                    SELECT CGMV.NAME_TYPE
                    FROM GCCOM_LOST_HISTORY_SS GLH
                        INNER JOIN GCCOM_MASTER_VALUES CGMV ON GLH.COD_VALUE = CGMV.COD_VALUE
                    WHERE GLH.ID_SECTOR_SUPPLY = CORE.ID_SECTOR_SUPPLY 
                        AND TO_DATE(CORE.DAY, 'YYYYMMDD') BETWEEN GLH.INIT_DATE AND GLH.END_DATE AND ROWNUM < 2
                ), '') AS ITC,
             CORE.CONSUM_TYPE,
             CORE.VALUE_1,
             CORE.VALUE_2,  
             CORE.VALUE_3,
             CORE.VALUE_4,
             CORE.VALUE_5,
             CORE.VALUE_6,
             CORE.VALUE_7,
             CORE.VALUE_8,
             CORE.VALUE_9,
             CORE.VALUE_10,
             CORE.VALUE_11,
             CORE.VALUE_12,
             CORE.VALUE_13,
             CORE.VALUE_14,
             CORE.VALUE_15,
             CORE.VALUE_16,
             CORE.VALUE_17,
             CORE.VALUE_18,
             CORE.VALUE_19,
             CORE.VALUE_20,
             CORE.VALUE_21,
             CORE.VALUE_22,
             CORE.VALUE_23,
             CORE.VALUE_24,
             CORE.VALUE_25,
             CORE.SOURCE_1,
             CORE.SOURCE_2,  
             CORE.SOURCE_3,
             CORE.SOURCE_4,
             CORE.SOURCE_5,
             CORE.SOURCE_6,
             CORE.SOURCE_7,
             CORE.SOURCE_8,
             CORE.SOURCE_9,
             CORE.SOURCE_10,
             CORE.SOURCE_11,
             CORE.SOURCE_12,
             CORE.SOURCE_13,
             CORE.SOURCE_14,
             CORE.SOURCE_15,
             CORE.SOURCE_16,
             CORE.SOURCE_17,
             CORE.SOURCE_18,
             CORE.SOURCE_19,
             CORE.SOURCE_20,
             CORE.SOURCE_21,
             CORE.SOURCE_22,
             CORE.SOURCE_23,
             CORE.SOURCE_24,
             CORE.SOURCE_25,
             CORE.QUALITY_1,
             CORE.QUALITY_2,  
             CORE.QUALITY_3,
             CORE.QUALITY_4,
             CORE.QUALITY_5,
             CORE.QUALITY_6,
             CORE.QUALITY_7,
             CORE.QUALITY_8,
             CORE.QUALITY_9,
             CORE.QUALITY_10,
             CORE.QUALITY_11,
             CORE.QUALITY_12,
             CORE.QUALITY_13,
             CORE.QUALITY_14,
             CORE.QUALITY_15,
             CORE.QUALITY_16,
             CORE.QUALITY_17,
             CORE.QUALITY_18,
             CORE.QUALITY_19,
             CORE.QUALITY_20,
             CORE.QUALITY_21,
             CORE.QUALITY_22,
             CORE.QUALITY_23,
             CORE.QUALITY_24,
             CORE.QUALITY_25,
             CORE.DAY,
             ORI.DESCRIPTION AS ORIGIN,
             CORE.ID_CONTRACTED_SERVICE,
             CORE.BAJA,
             CORE.GESTION_ATR,
             NVL ((SELECT IND_COGENERATION 
                   FROM GCCOM_CONTSERV_SPECIALTYPES SP
                   WHERE CORE.ID_CONTRACTED_SERVICE = SP.ID_CONTRACTED_SERVICE 
                     AND (SP.END_DATE IS NULL OR SP.END_DATE >= TO_DATE (20130228   , 'YYYYMMDD'))
                     AND SP.INI_DATE <= TO_DATE (20130228   , 'YYYYMMDD')), 0) AS COGENERADOR,
             CORE.NISC
      FROM   CORE,
             GCGT_ELECTRIC_ATTRIBUTES EATT,
             GCCOM_COMPANY COM,
             GCGT_ME_RATE_METER RM,
             GCGT_ME_COMBINATION_USAGE_TYPE CUT,
             GCCOM_FARE FAR,
             GCGT_RE_MP_CUSTOMER_TYPE CT,
             GCGT_RE_ORIGIN ORI
    WHERE    EATT.ID_SECTOR_SUPPLY = CORE.ID_SECTOR_SUPPLY
             AND COM.ID_COMPANY = CORE.ID_DISTRIBUTER
             AND CUT.ID_COMBINATION_USAGE_TYPE (+) = CORE.ID_COMBINATION_USAGE_TYPE
             AND CUT.ID_RATE_METER = RM.ID_RATE_METER (+)
             AND FAR.ID_FARE (+) = RM.ID_FARE
             AND (CT.COD_DEVELOP = CORE.MP_FUNCTION or CORE.MP_FUNCTION is null)
             AND ORI.COD_DEVELOP = CORE.ORIGIN;

解释计划如下所示:

    PLAN_TABLE_OUTPUT
    -------------------------------------------------------------------------------------------------------------------------------------------------------------
    Plan hash value: 398847285
    -------------------------------------------------------------------------------------------------------------------------------------------------
    | Id  | Operation                              | Name                           | Rows  | Bytes |TempSpc| Cost (%CPU)| Time     | Pstart| Pstop |
    -------------------------------------------------------------------------------------------------------------------------------------------------
    |   0 | SELECT STATEMENT                       |                                |   186K|    63M|    |  1352K  (1)| 04:30:26 |  |       |
    |   1 |  SORT AGGREGATE                        |                                |     1 |    28 |    |       |          |       |       |
    |*  2 |   COUNT STOPKEY                        |                                |       |       |    |       |          |       |       |
    |   3 |    PARTITION RANGE ALL                 |                                |     2 |    56 |    |    75   (0)| 00:00:01 |     1 |   108 |
    |*  4 |     TABLE ACCESS BY LOCAL INDEX ROWID  | GCCOM_DELIVERY_NOTE            |     2 |    56 |    |    75   (0)| 00:00:01 |     1 |   108 |
    |*  5 |      INDEX RANGE SCAN                  | IDX_GCCOM_DELIVERY_NOTE_28     |    33 |       |    |    65   (0)| 00:00:01 |     1 |   108 |
    |   6 |  SORT AGGREGATE                        |                                |     1 |    30 |    |       |          |       |       |
    |*  7 |   COUNT STOPKEY                        |                                |       |       |    |       |          |       |       |
    |   8 |    PARTITION RANGE ALL                 |                                |     2 |    60 |    |    75   (0)| 00:00:01 |     1 |   108 |
    |*  9 |     TABLE ACCESS BY LOCAL INDEX ROWID  | GCCOM_DELIVERY_NOTE            |     2 |    60 |    |    75   (0)| 00:00:01 |     1 |   108 |
    |* 10 |      INDEX RANGE SCAN                  | IDX_GCCOM_DELIVERY_NOTE_28     |    33 |       |    |    65   (0)| 00:00:01 |     1 |   108 |
    |  11 |  SORT AGGREGATE                        |                                |     1 |    30 |    |       |          |       |       |
    |* 12 |   COUNT STOPKEY                        |                                |       |       |    |       |          |       |       |
    |* 13 |    FILTER                              |                                |       |       |    |       |          |       |       |
    |  14 |     PARTITION RANGE ALL                |                                |    32 |   960 |    |    75   (0)| 00:00:01 |     1 |   108 |
    |* 15 |      TABLE ACCESS BY LOCAL INDEX ROWID | GCCOM_DELIVERY_NOTE            |    32 |   960 |    |    75   (0)| 00:00:01 |     1 |   108 |
    |* 16 |       INDEX RANGE SCAN                 | IDX_GCCOM_DELIVERY_NOTE_28     |    33 |       |    |    65   (0)| 00:00:01 |     1 |   108 |
    |  17 |     SORT AGGREGATE                     |                                |     1 |    14 |    |       |          |       |       |
    |  18 |      PARTITION RANGE ALL               |                                |     2 |    28 |    |    75   (0)| 00:00:01 |     1 |   108 |
    |* 19 |       TABLE ACCESS BY LOCAL INDEX ROWID| GCCOM_DELIVERY_NOTE            |     2 |    28 |    |    75   (0)| 00:00:01 |     1 |   108 |
    |* 20 |        INDEX RANGE SCAN                | IDX_GCCOM_DELIVERY_NOTE_28     |    33 |       |    |    65   (0)| 00:00:01 |     1 |   108 |
    |  21 |  SORT AGGREGATE                        |                                |     1 |    12 |    |       |          |       |       |
    |* 22 |   INDEX RANGE SCAN                     | IDX_GCGT_RE_READING_E_16       |     1 |    12 |    |     1   (0)| 00:00:01 |  |       |
    |  23 |  SORT AGGREGATE                        |                                |     1 |     6 |    |       |          |       |       |
    |* 24 |   INDEX RANGE SCAN                     | IDX_GCGT_REMEASPOINT_SSMP_01   |     1 |     6 |    |     1   (0)| 00:00:01 |  |       |
    |* 25 |  COUNT STOPKEY                         |                                |       |       |    |       |          |       |       |
    |  26 |   NESTED LOOPS                         |                                |       |       |    |       |          |       |       |
    |  27 |    NESTED LOOPS                        |                                |     1 |    61 |    |     2   (0)| 00:00:01 |  |       |
    |* 28 |     TABLE ACCESS BY INDEX ROWID        | GCCOM_LOST_HISTORY_SS          |     1 |    30 |    |     1   (0)| 00:00:01 |  |       |
    |* 29 |      INDEX RANGE SCAN                  | IDX_GCCOMLOSTHISTORYSS_01      |     1 |       |    |     1   (0)| 00:00:01 |  |       |
    |* 30 |     INDEX UNIQUE SCAN                  | PK_GCCOM_MASTER_VALUES         |     1 |       |    |     1   (0)| 00:00:01 |  |       |
    |  31 |    TABLE ACCESS BY INDEX ROWID         | GCCOM_MASTER_VALUES            |     1 |    31 |    |     1   (0)| 00:00:01 |  |       |
    |* 32 |  TABLE ACCESS BY INDEX ROWID           | GCCOM_CONTSERV_SPECIALTYPES    |     1 |    24 |    |     1   (0)| 00:00:01 |  |       |
    |* 33 |   INDEX RANGE SCAN                     | IDX_GCCOMCONTSERVSPETYP_01     |     1 |       |    |     1   (0)| 00:00:01 |  |       |
    |* 34 |  FILTER                                |                                |       |       |    |       |          |       |       |
    |* 35 |   HASH JOIN                            |                                |   186K|    63M|    |   146K  (1)| 00:29:16 |  |       |
    |  36 |    TABLE ACCESS FULL                   | GCCOM_COMPANY                  |  1116 | 34596 |    |     9   (0)| 00:00:01 |  |       |
    |* 37 |    HASH JOIN                           |                                |   194K|    60M|    22M|   146K  (1)| 00:29:16 |       |       |
    |  38 |     PART JOIN FILTER CREATE            | :BF0000                        |   722K|    13M|    |  5316   (1)| 00:01:04 |  |       |
    |  39 |      PARTITION REFERENCE ALL           |                                |   722K|    13M|    |  5316   (1)| 00:01:04 |     1 |    10 |
    |  40 |       TABLE ACCESS FULL                | GCGT_ELECTRIC_ATTRIBUTES       |   722K|    13M|    |  5316   (1)| 00:01:04 |     1 |    10 |
    |* 41 |     HASH JOIN                          |                                |   207K|    61M|    |   136K  (1)| 00:27:21 |  |       |
    |  42 |      TABLE ACCESS FULL                 | GCGT_RE_ORIGIN                 |     3 |    42 |    |     3   (0)| 00:00:01 |  |       |
    |* 43 |      HASH JOIN                         |                                |   207K|    58M|    22M|   136K  (1)| 00:27:21 |       |       |
    |  44 |       PARTITION REFERENCE ALL          |                                |   486K|    17M|    |  4618   (1)| 00:00:56 |     1 |    10 |
    |* 45 |        TABLE ACCESS FULL               | GCCOM_CONTRACT                 |   486K|    17M|    |  4618   (1)| 00:00:56 |     1 |    10 |
    |* 46 |       HASH JOIN                        |                                |   207K|    50M|    19M|   128K  (1)| 00:25:41 |       |       |
    |  47 |        PART JOIN FILTER CREATE         | :BF0001                        |   286K|    16M|    |  7118   (1)| 00:01:26 |  |       |
    |  48 |         PARTITION HASH ALL             |                                |   286K|    16M|    |  7118   (1)| 00:01:26 |     1 |    16 |
    |* 49 |          TABLE ACCESS FULL             | GCCOM_CONTRACTED_SERVICE       |   286K|    16M|    |  7118   (1)| 00:01:26 |     1 |    16 |
    |* 50 |        HASH JOIN RIGHT OUTER           |                                |   559K|   104M|    |   114K  (1)| 00:22:57 |  |       |
    |  51 |         TABLE ACCESS FULL              | GCCOM_FARE                     |   374 |  3366 |    |     6   (0)| 00:00:01 |  |       |
    |* 52 |         HASH JOIN RIGHT OUTER          |                                |   559K|    99M|    |   114K  (1)| 00:22:57 |  |       |
    |  53 |          TABLE ACCESS FULL             | GCGT_ME_RATE_METER             |    59 |   590 |    |     3   (0)| 00:00:01 |  |       |
    |  54 |          NESTED LOOPS SEMI             |                                |   559K|    94M|    |   114K  (1)| 00:22:57 |  |       |
    |* 55 |           HASH JOIN                    |                                |   559K|    89M|    74M|   114K  (1)| 00:22:57 |       |       |
    |* 56 |            TABLE ACCESS FULL           | GCGT_ME_MEA_CTYPE_HIST         |  2115K|    50M|    | 50950   (1)| 00:10:12 |  |       |
    |* 57 |            HASH JOIN RIGHT OUTER       |                                |   521K|    70M|    | 56226   (1)| 00:11:15 |  |       |
    |  58 |             TABLE ACCESS FULL          | GCGT_ME_COMBINATION_USAGE_TYPE |   378 |  3024 |    |     4   (0)| 00:00:01 |  |       |
    |* 59 |             HASH JOIN                  |                                |   521K|    66M|    67M| 56219   (1)| 00:11:15 |       |       |
    |* 60 |              HASH JOIN                 |                                |   521K|    61M|    25M| 18543   (1)| 00:03:43 |       |       |
    |  61 |               PARTITION HASH AND       |                                |   771K|    16M|    |  8246   (1)| 00:01:39 |KEY(AP)|KEY(AP)|
    |  62 |                TABLE ACCESS FULL       | GCCOM_SECTOR_SUPPLY            |   771K|    16M|    |  8246   (1)| 00:01:39 |KEY(AP)|KEY(AP)|
    |* 63 |               HASH JOIN                |                                |   521K|    50M|    |  6235   (1)| 00:01:15 |  |       |
    |* 64 |                HASH JOIN               |                                |   260 | 11440 |    |    15   (7)| 00:00:01 |  |       |
    |  65 |                 MERGE JOIN CARTESIAN   |                                |    15 |   435 |    |    12   (0)| 00:00:01 |  |       |
    |  66 |                  TABLE ACCESS FULL     | GCGT_RE_MP_CUSTOMER_TYPE       |     5 |    70 |    |     3   (0)| 00:00:01 |  |       |
    |  67 |                  BUFFER SORT           |                                |     3 |    45 |    |     9   (0)| 00:00:01 |  |       |
    |  68 |                   TABLE ACCESS FULL    | GCGT_RE_MODE_TYPE              |     3 |    45 |    |     2   (0)| 00:00:01 |  |       |
    |  69 |                 VIEW                   | index$_join$_011               |    52 |   780 |    |     3  (34)| 00:00:01 |  |       |
    |* 70 |                  HASH JOIN             |                                |       |       |    |       |          |       |       |
    |  71 |                   INDEX FAST FULL SCAN | FK_RE_MP_NATUR_RE_MODE_TYPE_01 |    52 |   780 |    |     1   (0)| 00:00:01 |  |       |
    |  72 |                   INDEX FAST FULL SCAN | PK_GCGT_RE_MP_NATURE           |    52 |   780 |    |     1   (0)| 00:00:01 |  |       |
    |* 73 |                TABLE ACCESS FULL       | GCGT_RE_MEASUREMENT_POINT      |   454K|    25M|    |  6210   (1)| 00:01:15 |  |       |
    |  74 |              TABLE ACCESS FULL         | GCGT_ME_MEASURER               |  7195K|    68M|    | 26770   (1)| 00:05:22 |  |       |
    |* 75 |           INDEX UNIQUE SCAN            | IDX_GCGTMEUSAGETYPEMETER_08    |    10M|    96M|    |     1   (0)| 00:00:01 |  |       |
    |* 76 |   TABLE ACCESS BY GLOBAL INDEX ROWID   | GCGT_RE_CONSUM_H_E             |     1 |    25 |    |     7   (0)| 00:00:01 |    87 |    87 |
    |* 77 |    INDEX RANGE SCAN                    | IDX_GCGTRECONSUMHE02           |     1 |       |    |     1   (0)| 00:00:01 |  |       |
    -------------------------------------------------------------------------------------------------------------------------------------------------
    147 filas seleccionadas.

我尝试了索引:

索引IDX_GCCOM_DELIVERY_NOTE_30 在GCCOM_DELIVERY_NOTE(“ID_CONTRACTED_SERVICE”,TO_CHAR(“FORECAST_BILLING_DATE”,“YYYYMM”))

索引IDX_GCCOM_DELIVERY_NOTE_31 在GCCOM_DELIVERY_NOTE(“ID_CONTRACTED_SERVICE”,“DELIVERY_NOTE_STATUS”,“IND_SIMULATED”,TO_CHAR(“FORECAST_BILLING_DATE”,“YYYYMM”));

索引IDX_GCCOMLOSTHISTORYSS_02 在GCCOM_LOST_HISTORY_SS上(“ID_SECTOR_SUPPLY”,“END_DATE”,“COD_VALUE”);

但是解释计划没有显示出很大的改进:

    PLAN_TABLE_OUTPUT
    --------------------------------------------------------------------------------------------------------------------------------------------------------------------
    Plan hash value: 2244861761
    --------------------------------------------------------------------------------------------------------------------------------------------------
    | Id  | Operation                               | Name                           | Rows  | Bytes |TempSpc| Cost (%CPU)| Time     | Pstart| Pstop |
    --------------------------------------------------------------------------------------------------------------------------------------------------
    |   0 | SELECT STATEMENT                        |                                |   186K|    63M|    |  1352K  (1)| 04:30:26 |  |       |
    |   1 |  SORT AGGREGATE                         |                                |     1 |    25 |    |       |          |       |       |
    |*  2 |   COUNT STOPKEY                         |                                |       |       |    |       |          |       |       |
    |   3 |    INLIST ITERATOR                      |                                |       |       |    |       |          |       |       |
    |*  4 |     INDEX RANGE SCAN                    | IDX_GCCOM_DELIVERY_NOTE_31     |     2 |    50 |    |     1   (0)| 00:00:01 |  |       |
    |   5 |  SORT AGGREGATE                         |                                |     1 |    27 |    |       |          |       |       |
    |*  6 |   COUNT STOPKEY                         |                                |       |       |    |       |          |       |       |
    |*  7 |    TABLE ACCESS BY GLOBAL INDEX ROWID   | GCCOM_DELIVERY_NOTE            |     2 |    54 |    |     1   (0)| 00:00:01 | ROWID | ROWID |
    |*  8 |     INDEX RANGE SCAN                    | IDX_GCCOM_DELIVERY_NOTE_30     |     1 |       |    |     1   (0)| 00:00:01 |  |       |
    |   9 |  SORT AGGREGATE                         |                                |     1 |    27 |    |       |          |       |       |
    |* 10 |   COUNT STOPKEY                         |                                |       |       |    |       |          |       |       |
    |* 11 |    TABLE ACCESS BY GLOBAL INDEX ROWID   | GCCOM_DELIVERY_NOTE            |     1 |    27 |    |     1   (0)| 00:00:01 | ROWID | ROWID |
    |* 12 |     INDEX RANGE SCAN                    | IDX_GCCOM_DELIVERY_NOTE_30     |     1 |       |    |     1   (0)| 00:00:01 |  |       |
    |  13 |      SORT AGGREGATE                     |                                |     1 |    19 |    |       |          |       |       |
    |  14 |       TABLE ACCESS BY GLOBAL INDEX ROWID| GCCOM_DELIVERY_NOTE            |     2 |    38 |    |     1   (0)| 00:00:01 | ROWID | ROWID |
    |* 15 |        INDEX RANGE SCAN                 | IDX_GCCOM_DELIVERY_NOTE_30     |     1 |       |    |     1   (0)| 00:00:01 |  |       |
    |  16 |  SORT AGGREGATE                         |                                |     1 |    12 |    |       |          |       |       |
    |* 17 |   INDEX RANGE SCAN                      | IDX_GCGT_RE_READING_E_16       |     1 |    12 |    |     1   (0)| 00:00:01 |  |       |
    |  18 |  SORT AGGREGATE                         |                                |     1 |     6 |    |       |          |       |       |
    |* 19 |   INDEX RANGE SCAN                      | IDX_GCGT_REMEASPOINT_SSMP_01   |     1 |     6 |    |     1   (0)| 00:00:01 |  |       |
    |* 20 |  COUNT STOPKEY                          |                                |       |       |    |       |          |       |       |
    |  21 |   NESTED LOOPS                          |                                |       |       |    |       |          |       |       |
    |  22 |    NESTED LOOPS                         |                                |     1 |    61 |    |     2   (0)| 00:00:01 |  |       |
    |* 23 |     TABLE ACCESS BY INDEX ROWID         | GCCOM_LOST_HISTORY_SS          |     1 |    30 |    |     1   (0)| 00:00:01 |  |       |
    |* 24 |      INDEX RANGE SCAN                   | IDX_GCCOMLOSTHISTORYSS_02      |     1 |       |    |     1   (0)| 00:00:01 |  |       |
    |* 25 |     INDEX UNIQUE SCAN                   | PK_GCCOM_MASTER_VALUES         |     1 |       |    |     1   (0)| 00:00:01 |  |       |
    |  26 |    TABLE ACCESS BY INDEX ROWID          | GCCOM_MASTER_VALUES            |     1 |    31 |    |     1   (0)| 00:00:01 |  |       |
    |* 27 |  TABLE ACCESS BY INDEX ROWID            | GCCOM_CONTSERV_SPECIALTYPES    |     1 |    24 |    |     1   (0)| 00:00:01 |  |       |
    |* 28 |   INDEX RANGE SCAN                      | IDX_GCCOMCONTSERVSPETYP_01     |     1 |       |    |     1   (0)| 00:00:01 |  |       |
    |* 29 |  FILTER                                 |                                

我正在比较应用索引之前和之后的解释计划。

我看到Access路径有一些变化,但整体结果是一样的。

查询有任何改进吗?

这些是表访问已满,我是否必须在它们上面编写索引?

        Line 43:        |  36 |    TABLE ACCESS FULL                   | GCCOM_COMPANY                  |  1116 | 34596 |    |     9   (0)| 00:00:01 |  |       |
        Line 47:        |  40 |       TABLE ACCESS FULL                | GCGT_ELECTRIC_ATTRIBUTES       |   722K|    13M|    |  5316   (1)| 00:01:04 |     1 |    10 |
        Line 49:        |  42 |      TABLE ACCESS FULL                 | GCGT_RE_ORIGIN                 |     3 |    42 |    |     3   (0)| 00:00:01 |  |       |
        Line 52:        |* 45 |        TABLE ACCESS FULL               | GCCOM_CONTRACT                 |   486K|    17M|    |  4618   (1)| 00:00:56 |     1 |    10 |
        Line 56:        |* 49 |          TABLE ACCESS FULL             | GCCOM_CONTRACTED_SERVICE       |   286K|    16M|    |  7118   (1)| 00:01:26 |     1 |    16 |
        Line 58:        |  51 |         TABLE ACCESS FULL              | GCCOM_FARE                     |   374 |  3366 |    |     6   (0)| 00:00:01 |  |       |
        Line 60:        |  53 |          TABLE ACCESS FULL             | GCGT_ME_RATE_METER             |    59 |   590 |    |     3   (0)| 00:00:01 |  |       |
        Line 63:        |* 56 |            TABLE ACCESS FULL           | GCGT_ME_MEA_CTYPE_HIST         |  2115K|    50M|    | 50950   (1)| 00:10:12 |  |       |
        Line 65:        |  58 |             TABLE ACCESS FULL          | GCGT_ME_COMBINATION_USAGE_TYPE |   378 |  3024 |    |     4   (0)| 00:00:01 |  |       |
        Line 69:        |  62 |                TABLE ACCESS FULL       | GCCOM_SECTOR_SUPPLY            |   771K|    16M|    |  8246   (1)| 00:01:39 |KEY(AP)|KEY(AP)|
        Line 73:        |  66 |                  TABLE ACCESS FULL     | GCGT_RE_MP_CUSTOMER_TYPE       |     5 |    70 |    |     3   (0)| 00:00:01 |  |       |
        Line 75:        |  68 |                   TABLE ACCESS FULL    | GCGT_RE_MODE_TYPE              |     3 |    45 |    |     2   (0)| 00:00:01 |  |       |
        Line 80:        |* 73 |                TABLE ACCESS FULL       | GCGT_RE_MEASUREMENT_POINT      |   454K|    25M|    |  6210   (1)| 00:01:15 |  |       |
        Line 81:        |  74 |              TABLE ACCESS FULL         | GCGT_ME_MEASURER               |  7195K|    68M|    | 26770   (1)| 00:05:22 |  |       |

我没有考虑用GATHER_TABLE_STATS的提示执行查询,让我试试!!

我回来了结果!!

0 个答案:

没有答案