查询运行时间过长

时间:2014-08-04 14:29:57

标签: sql performance oracle explain

处理此查询以加快速度

我正在努力避免那些TABLE ACCESS FULL并分析应用了正确的基数,但这些是唯一可以提高性能的东西吗?

任何额外的观点,将不胜感激。

    SELECT  DISTINCT
               (SELECT CM.COD_USER_COMPANY FROM GCCOM_COMPANY CM WHERE SS.ID_SELLER = CM.ID_COMPANY ) AS SOCIEDAD,
                SE.COD_USER AS SECTOR,
                (SELECT CM.COD_USER_COMPANY FROM GCCOM_COMPANY CM WHERE SS.ID_DISTRIBUTER = CM.ID_COMPANY) AS DISTRIBUIDORA,
    FROM    GCGT_RE_READING_COOR_CENTER CC
                INNER JOIN GCGT_RE_READING_UNIT RU ON CC.ID_CENTER = RU.ID_CENTER
                INNER JOIN GCGT_WO_AREA_HIERARCHY WH ON WH.ID_PARENT_AREA = CC.ID_AREA
                INNER JOIN GCGT_WO_EXECUTION_AREA WA ON WA.ID_AREA = RU.ID_AREA AND  WA.ID_AREA = WH.ID_AREA
                INNER JOIN GCGT_RE_ROUTE R ON  R.ID_CENTER = CC.ID_CENTER AND R.ID_CENTER = RU.ID_CENTER
                INNER JOIN GCGT_RE_MEA_POINT_ROUTE_HIST RHIST ON R.ID_ROUTE = RHIST.ID_ROUTE
                INNER JOIN GCGT_RE_ITINERARY IT ON IT.ID_RU= RU.ID_RU  AND IT.ID_ROUTE = RHIST.ID_ROUTE
                INNER JOIN GCGT_RE_ITINERARY_MACRO ITM ON IT.ID_ITINERARY_MACRO = ITM.ID_MACROITINERARY
                INNER JOIN GCGT_RE_MEASUREMENT_POINT MP ON  MP.ID_MEASURING_POINT = RHIST.ID_MEASURING_POINT
                INNER JOIN GCGT_RE_MPOINT_HIST MPHIST ON MP.ID_MEASURING_POINT = MPHIST.ID_MEASURING_POINT
                INNER JOIN GCGT_ME_MEASURER ME ON ME.ID_MEASURER = MPHIST.ID_MEASURER
                INNER JOIN GCGT_ME_MEA_POINT_DEVICE_HIST DEVHIST ON DEVHIST.ID_MEASURING_POINT = MPHIST.ID_MEASURING_POINT   
                INNER JOIN GCGT_ME_DEVICE DEV ON DEVHIST.ID_DEVICE = DEV.ID_DEVICE AND DEV.ID_DEVICE = ME.ID_DEVICE
                INNER JOIN GCGT_ME_MEA_CTYPE_HIST CTHIST ON MPHIST.ID_MEASURER = CTHIST.ID_MEASURER            
                INNER JOIN GCCOM_SECTOR_SUPPLY SS ON SS.ID_SECTOR_SUPPLY = MP.ID_SECTOR_SUPPLY
                INNER JOIN GCCOM_SECTOR SE ON SE.ID_SECTOR = SS.ID_SECTOR 
                INNER JOIN GCCOM_CONTRACTED_SERVICE CS ON SS.ID_SECTOR_SUPPLY = CS.ID_SECTOR_SUPPLY AND CS.ID_SECTOR_SUPPLY = MP.ID_SECTOR_SUPPLY
                INNER JOIN GCCOM_COMPANY COM ON COM.ID_COMPANY = SS.ID_SELLER OR COM.ID_COMPANY = SS.ID_DISTRIBUTER
                INNER JOIN GCGT_RE_READING_E RE ON RE.ID_MEASURING_POINT = MPHIST.ID_MEASURING_POINT AND RE.ID_ITINERARY = IT.ID_ITINERARY AND CTHIST.COD_USAGE_TYPE = RE.CONSUM_TYPE AND MPHIST.ID_MEASURER = RE.ID_MEASURER
                INNER JOIN GCCOM_CONTRACT CO ON CS.ID_CONTRACT = CO.ID_CONTRACT
                INNER JOIN GCCC_CUSTOMER CU ON CO.ID_CUSTOMER = CU.ID_CUSTOMER
                INNER JOIN GCGT_ME_COMBINATION_USAGE_TYPE CUT ON MPHIST.ID_COMBINATION_USAGE_TYPE = CUT.ID_COMBINATION_USAGE_TYPE AND CUT.COD_DEVICE_TYPE = DEV.COD_DEVICE_TYPE
                INNER JOIN GCGT_ME_RATE_METER RM ON RM.ID_RATE_METER = MPHIST.ID_RATE_METER 
                                                 AND RM.COD_SPECIALIZATION = SE.COD_DEVELOP
                INNER JOIN GCCOM_FARE FA ON RM.ID_FARE = FA.ID_FARE AND FA.ID_SECTOR = SE.ID_SECTOR
    WHERE  (CC.COD_GESTION IS NULL OR CC.COD_GESTION = 'TYPCLI0003')
                AND (WH.COD_GESTION IS NULL OR WH.COD_GESTION = 'TYPCLI0003')
                AND (WA.COD_GESTION IS NULL OR WA.COD_GESTION= 'TYPCLI0003')
                AND (RU.COD_GESTION IS NULL OR RU.COD_GESTION = 'TYPCLI0003')
                AND (R.COD_GESTION IS NULL OR R.COD_GESTION = 'TYPCLI0003')
                AND (RM.COD_GESTION IS NULL OR RM.COD_GESTION = 'TYPCLI0003')
                AND (DEV.COD_GESTION IS NULL OR DEV.COD_GESTION = 'TYPCLI0003')
                AND DEV.COD_DEVICE_TYPE = 'TAPAR00001'
                AND SE.COD_DEVELOP = 'SECTOR0001'
                AND RHIST.INIT_DATE <= TO_DATE('20130630','YYYYMMDD')
                AND (RHIST.END_DATE IS NULL OR RHIST.END_DATE >= TO_DATE('20130101','YYYYMMDD') )
                AND 20130630 >= CTHIST.FROM_DATE
                AND (CTHIST.TO_DATE IS NULL OR 20130101 <= CTHIST.TO_DATE)
                AND 20130630 >= MPHIST.FROM_DATE
                AND (MPHIST.TO_DATE IS NULL OR 20130101 <= MPHIST.TO_DATE)
                AND RE.DAY BETWEEN 20130101 AND 20130630
                AND 3000000 = (SELECT COM.ID_COMPANY FROM GCCOM_COMPANY COM WHERE COM.ID_COMPANY = SS.ID_SELLER) 
                AND 0 = (
                    SELECT SUM(R2.ENERGY)
                    FROM GCGT_RE_READING_E R2
                    WHERE R2.DAY BETWEEN 20130101 AND 20130630
                    AND R2.ID_MEASURING_POINT = RE.ID_MEASURING_POINT 
                    AND R2.ID_MEASURER = RE.ID_MEASURER
                    AND R2.ORIGIN = RE.ORIGIN
                    AND R2.STATE <>6
                    AND R2.ACTIVE =1
                    AND R2.CONSUM_TYPE =  RE.CONSUM_TYPE 
                    AND ((R2.ORIGIN = 'TEL' AND R2.RELEVANT = 1) OR R2.ORIGIN <> 'TEL' )
                )
    ORDER BY CUPS;

解释计划:

我在这里附上解释计划执行,供你检查。

    PLAN_TABLE_OUTPUT
    ------------------------------------------------------------------------------------------------------------------------------------------------------
    Plan hash value: 3130792258
    -----------------------------------------------------------------------------------------------------------------------------------------------------
    | Id  | Operation                                          | Name                           | Rows  | Bytes | Cost (%CPU)| Time     | Pstart| Pstop |
    -----------------------------------------------------------------------------------------------------------------------------------------------------
    |   0 | SELECT STATEMENT                                   |                                |     1 |   669 |  3888   (2)| 00:00:47 |       |       |
    |   1 |  TABLE ACCESS BY INDEX ROWID                       | GCCOM_COMPANY                  |     1 |     9 |     1   (0)| 00:00:01 |       |       |
    |*  2 |   INDEX UNIQUE SCAN                                | PK_GCCOM_COMPANY               |     1 |       |     1   (0)| 00:00:01 |       |       |
    |   3 |  TABLE ACCESS BY INDEX ROWID                       | GCCOM_COMPANY                  |     1 |     9 |     1   (0)| 00:00:01 |       |       |
    |*  4 |   INDEX UNIQUE SCAN                                | PK_GCCOM_COMPANY               |     1 |       |     1   (0)| 00:00:01 |       |       |
    |   5 |  SORT ORDER BY                                     |                                |     1 |   669 |  3888   (2)| 00:00:47 |       |       |
    |   6 |   HASH UNIQUE                                      |                                |     1 |   669 |  3887   (2)| 00:00:47 |       |       |
    |*  7 |    FILTER                                          |                                |       |       |            |          |       |       |
    |   8 |     NESTED LOOPS                                   |                                |     1 |   669 |  3884   (2)| 00:00:47 |       |       |
    |* 18 |               HASH JOIN                            |                                |     4 |  1596 |  3874   (2)| 00:00:47 |       |       |
    |* 19 |                HASH JOIN                           |                                |    17 |  6528 |  3872   (2)| 00:00:47 |       |       |
    |* 20 |                 HASH JOIN                          |                                |    29 | 10121 |  3865   (2)| 00:00:47 |       |       |
    |  21 |                  TABLE ACCESS BY INDEX ROWID       | GCCOM_SECTOR                   |     1 |    18 |     1   (0)| 00:00:01 |       |       |
    |* 22 |                   INDEX RANGE SCAN                 | IDX$$_00000002                 |     1 |       |     1   (0)| 00:00:01 |       |       |
    |* 23 |                  HASH JOIN                         |                                |    29 |  9599 |  3864   (2)| 00:00:47 |       |       |
    |* 24 |                   TABLE ACCESS BY INDEX ROWID      | GCGT_ME_RATE_METER             |     4 |   128 |     1   (0)| 00:00:01 |       |       |
    |* 25 |                    INDEX RANGE SCAN                | IDX_FK_ME_RATE_TY_RE_SPEC_01   |    23 |       |     1   (0)| 00:00:01 |       |       |
    |  26 |                   NESTED LOOPS                     |                                |       |       |            |          |       |       |
    |  27 |                    NESTED LOOPS                    |                                |   381 |   111K|  3862   (2)| 00:00:47 |       |       |
    |  28 |                     NESTED LOOPS                   |                                |   170 | 45220 |  3658   (2)| 00:00:44 |       |       |
    |  29 |                      NESTED LOOPS                  |                                |   170 | 43010 |  3607   (2)| 00:00:44 |       |       |
    |* 30 |                       HASH JOIN                    |                                |  1047 |   229K|  2613   (1)| 00:00:32 |       |       |
    |  31 |                        NESTED LOOPS                |                                |       |       |            |          |       |       |
    |  32 |                         NESTED LOOPS               |                                |   706 |   131K|  2255   (1)| 00:00:28 |       |       |
    |* 33 |                          HASH JOIN                 |                                |   706 | 91074 |  2043   (1)| 00:00:25 |       |       |
    |* 34 |                           TABLE ACCESS FULL        | GCGT_WO_AREA_HIERARCHY         |   348 |  8004 |     4   (0)| 00:00:01 |       |       |
    |* 35 |                           HASH JOIN                |                                |   119K|    12M|  2038   (1)| 00:00:25 |       |       |
    |* 36 |                            TABLE ACCESS FULL       | GCGT_WO_EXECUTION_AREA         |   349 |  5933 |     5   (0)| 00:00:01 |       |       |
    |* 37 |                            HASH JOIN               |                                |   119K|    10M|  2032   (1)| 00:00:25 |       |       |
    |* 38 |                             TABLE ACCESS FULL      | GCGT_RE_READING_COOR_CENTER    |   116 |  3364 |     4   (0)| 00:00:01 |       |       |
    |* 39 |                             HASH JOIN              |                                |   190K|    10M|  2026   (1)| 00:00:25 |       |       |
    |* 40 |                              TABLE ACCESS FULL     | GCGT_RE_READING_UNIT           |   190 |  6840 |     5   (0)| 00:00:01 |       |       |
    |  41 |                              TABLE ACCESS FULL     | GCGT_RE_ITINERARY              |   285K|  6689K|  2020   (1)| 00:00:25 |       |       |
    |* 42 |                          INDEX UNIQUE SCAN         | PK_GCGT_RE_ITINERARY_MACRO     |     1 |       |     1   (0)| 00:00:01 |       |       |
    |  43 |                         TABLE ACCESS BY INDEX ROWID| GCGT_RE_ITINERARY_MACRO        |     1 |    62 |     1   (0)| 00:00:01 |       |       |
    |* 44 |                        TABLE ACCESS FULL           | GCGT_RE_ROUTE                  |  5121 |   165K|   358   (1)| 00:00:05 |       |       |
    |* 45 |                       TABLE ACCESS BY INDEX ROWID  | GCGT_RE_MEA_POINT_ROUTE_HIST   |     1 |    29 |     1   (0)| 00:00:01 |       |       |
    |* 46 |                        INDEX RANGE SCAN            | FK_RE_MEA_POINTHIST_ROUTE_01   |     4 |       |     1   (0)| 00:00:01 |       |       |
    |  47 |                      TABLE ACCESS BY INDEX ROWID   | GCGT_RE_MEASUREMENT_POINT      |     1 |    13 |     1   (0)| 00:00:01 |       |       |
    |* 48 |                       INDEX UNIQUE SCAN            | PK_GCGT_RE_MEASUREMENT_POINT   |     1 |       |     1   (0)| 00:00:01 |       |       |
    |* 49 |                     INDEX RANGE SCAN               | IDX_GCGT_RE_MPOINHHIST_04      |     2 |       |     1   (0)| 00:00:01 |       |       |
    |  50 |                    TABLE ACCESS BY INDEX ROWID     | GCGT_RE_MPOINT_HIST            |     2 |    66 |     1   (0)| 00:00:01 |       |       |
    |  51 |                 TABLE ACCESS FULL                  | GCCOM_FARE                     |   374 | 13090 |     6   (0)| 00:00:01 |       |       |
    |  52 |                TABLE ACCESS BY INDEX ROWID         | GCGT_ME_COMBINATION_USAGE_TYPE |    89 |  1335 |     1   (0)| 00:00:01 |       |       |
    |* 53 |                 INDEX RANGE SCAN                   | IDX_FK_ME_COM_US_TY_DEV_TY_01  |    89 |       |     1   (0)| 00:00:01 |       |       |
    |* 54 |               TABLE ACCESS BY GLOBAL INDEX ROWID   | GCGT_RE_READING_E              |     1 |    40 |     1   (0)| 00:00:01 | ROWID | ROWID |
    |* 55 |                INDEX RANGE SCAN                    | IDX$$_00000003                 |     1 |       |     1   (0)| 00:00:01 |       |       |
    |* 56 |              TABLE ACCESS BY INDEX ROWID           | GCGT_ME_MEA_CTYPE_HIST         |     1 |    22 |     1   (0)| 00:00:01 |       |       |
    |* 57 |               INDEX RANGE SCAN                     | IDX_MEA_CTYPE_HIST_01          |     2 |       |     1   (0)| 00:00:01 |       |       |
    |  58 |             TABLE ACCESS BY GLOBAL INDEX ROWID     | GCCOM_SECTOR_SUPPLY            |     1 |    51 |     1   (0)| 00:00:01 | ROWID | ROWID |
    |* 59 |              INDEX RANGE SCAN                      | IDX_GCCOM_SECTOR_SUPPLY_21     |     1 |       |     1   (0)| 00:00:01 |       |       |
    |  60 |            TABLE ACCESS BY GLOBAL INDEX ROWID      | GCCOM_CONTRACTED_SERVICE       |     1 |    35 |     1   (0)| 00:00:01 | ROWID | ROWID |
    |* 61 |             INDEX RANGE SCAN                       | IDX_GCCOMCONTRACTEDSERVICE_28  |     1 |       |     1   (0)| 00:00:01 |       |       |
    |  62 |           TABLE ACCESS BY GLOBAL INDEX ROWID       | GCCOM_CONTRACT                 |     1 |    13 |     1   (0)| 00:00:01 | ROWID | ROWID |
    |* 63 |            INDEX UNIQUE SCAN                       | PK_GCCOM_CONTRACT              |     1 |       |     1   (0)| 00:00:01 |       |       |
    |  64 |          TABLE ACCESS BY INDEX ROWID               | GCGT_ME_MEASURER               |     1 |    16 |     1   (0)| 00:00:01 |       |       |
    |* 65 |           INDEX UNIQUE SCAN                        | PK_GCGT_ME_MEASURER            |     1 |       |     1   (0)| 00:00:01 |       |       |
    |* 66 |         TABLE ACCESS BY INDEX ROWID                | GCGT_ME_DEVICE                 |     1 |    41 |     1   (0)| 00:00:01 |       |       |
    |* 67 |          INDEX UNIQUE SCAN                         | PK_GCGT_ME_DEVICE              |     1 |       |     1   (0)| 00:00:01 |       |       |
    |* 68 |        TABLE ACCESS BY INDEX ROWID                 | GCGT_ME_MEA_POINT_DEVICE_HIST  |     1 |    14 |     1   (0)| 00:00:01 |       |       |
    |* 69 |         INDEX RANGE SCAN                           | IDX_GCGT_ME_MEAPOINTDEVHIST_04 |     1 |       |     1   (0)| 00:00:01 |       |       |
    |  70 |       PARTITION HASH ITERATOR                      |                                |     1 |    33 |     1   (0)| 00:00:01 |   KEY |   KEY |
    |  71 |        TABLE ACCESS BY LOCAL INDEX ROWID           | GCCC_CUSTOMER                  |     1 |    33 |     1   (0)| 00:00:01 |   KEY |   KEY |
    |* 72 |         INDEX UNIQUE SCAN                          | PK_GCCC_CUSTOMER               |     1 |       |     1   (0)| 00:00:01 |   KEY |   KEY |
    |* 73 |      INDEX FULL SCAN                               | PK_GCCOM_COMPANY               |     1 |     5 |     1   (0)| 00:00:01 |       |       |
    |* 74 |     INDEX UNIQUE SCAN                              | PK_GCCOM_COMPANY               |     1 |     5 |     1   (0)| 00:00:01 |       |       |
    |  75 |     SORT AGGREGATE                                 |                                |     1 |    39 |            |          |       |       |
    |* 76 |      TABLE ACCESS BY GLOBAL INDEX ROWID            | GCGT_RE_READING_E              |     1 |    39 |     2   (0)| 00:00:01 | ROWID | ROWID |
    |* 77 |       INDEX RANGE SCAN                             | IDX$$_00000003                 |     1 |       |     1   (0)| 00:00:01 |       |       |
    -----------------------------------------------------------------------------------------------------------------------------------------------------       140 filas seleccionadas.

请注意使用GATHER_PLAN_STATISTICS的解释计划,但似乎没有太大区别。

    PLAN_TABLE_OUTPUT
    ------------------------------------------------------------------------------------------------------------------------------------------------------
    Plan hash value: 3130792258
    -----------------------------------------------------------------------------------------------------------------------------------------------------
    | Id  | Operation                                          | Name                           | Rows  | Bytes | Cost (%CPU)| Time     | Pstart| Pstop |
    -----------------------------------------------------------------------------------------------------------------------------------------------------
    |   0 | SELECT STATEMENT                                   |                                |     1 |   669 |  3888   (2)| 00:00:47 |       |       |
    |   1 |  TABLE ACCESS BY INDEX ROWID                       | GCCOM_COMPANY                  |     1 |     9 |     1   (0)| 00:00:01 |       |       |
    |*  2 |   INDEX UNIQUE SCAN                                | PK_GCCOM_COMPANY               |     1 |       |     1   (0)| 00:00:01 |       |       |
    |   3 |  TABLE ACCESS BY INDEX ROWID                       | GCCOM_COMPANY                  |     1 |     9 |     1   (0)| 00:00:01 |       |       |
    |*  4 |   INDEX UNIQUE SCAN                                | PK_GCCOM_COMPANY               |     1 |       |     1   (0)| 00:00:01 |       |       |
    |   5 |  SORT ORDER BY                                     |                                |     1 |   669 |  3888   (2)| 00:00:47 |       |       |
    |   6 |   HASH UNIQUE                                      |                                |     1 |   669 |  3887   (2)| 00:00:47 |       |       |
    |*  7 |    FILTER                                          |                                |       |       |            |          |       |       |
    |   8 |     NESTED LOOPS                                   |                                |     1 |   669 |  3884   (2)| 00:00:47 |       |       |
    |* 18 |               HASH JOIN                            |                                |     4 |  1596 |  3874   (2)| 00:00:47 |       |       |
    |* 19 |                HASH JOIN                           |                                |    17 |  6528 |  3872   (2)| 00:00:47 |       |       |
    |* 20 |                 HASH JOIN                          |                                |    29 | 10121 |  3865   (2)| 00:00:47 |       |       |
    |  21 |                  TABLE ACCESS BY INDEX ROWID       | GCCOM_SECTOR                   |     1 |    18 |     1   (0)| 00:00:01 |       |       |
    |* 22 |                   INDEX RANGE SCAN                 | IDX$$_00000002                 |     1 |       |     1   (0)| 00:00:01 |       |       |
    |* 23 |                  HASH JOIN                         |                                |    29 |  9599 |  3864   (2)| 00:00:47 |       |       |
    |* 24 |                   TABLE ACCESS BY INDEX ROWID      | GCGT_ME_RATE_METER             |     4 |   128 |     1   (0)| 00:00:01 |       |       |
    |* 25 |                    INDEX RANGE SCAN                | IDX_FK_ME_RATE_TY_RE_SPEC_01   |    23 |       |     1   (0)| 00:00:01 |       |       |
    |  26 |                   NESTED LOOPS                     |                                |       |       |            |          |       |       |
    |  27 |                    NESTED LOOPS                    |                                |   381 |   111K|  3862   (2)| 00:00:47 |       |       |
    |  28 |                     NESTED LOOPS                   |                                |   170 | 45220 |  3658   (2)| 00:00:44 |       |       |
    |  29 |                      NESTED LOOPS                  |                                |   170 | 43010 |  3607   (2)| 00:00:44 |       |       |
    |* 30 |                       HASH JOIN                    |                                |  1047 |   229K|  2613   (1)| 00:00:32 |       |       |
    |  31 |                        NESTED LOOPS                |                                |       |       |            |          |       |       |
    |  32 |                         NESTED LOOPS               |                                |   706 |   131K|  2255   (1)| 00:00:28 |       |       |
    |* 33 |                          HASH JOIN                 |                                |   706 | 91074 |  2043   (1)| 00:00:25 |       |       |
    |* 34 |                           TABLE ACCESS FULL        | GCGT_WO_AREA_HIERARCHY         |   348 |  8004 |     4   (0)| 00:00:01 |       |       |
    |* 35 |                           HASH JOIN                |                                |   119K|    12M|  2038   (1)| 00:00:25 |       |       |
    |* 36 |                            TABLE ACCESS FULL       | GCGT_WO_EXECUTION_AREA         |   349 |  5933 |     5   (0)| 00:00:01 |       |       |
    |* 37 |                            HASH JOIN               |                                |   119K|    10M|  2032   (1)| 00:00:25 |       |       |
    |* 38 |                             TABLE ACCESS FULL      | GCGT_RE_READING_COOR_CENTER    |   116 |  3364 |     4   (0)| 00:00:01 |       |       |
    |* 39 |                             HASH JOIN              |                                |   190K|    10M|  2026   (1)| 00:00:25 |       |       |
    |* 40 |                              TABLE ACCESS FULL     | GCGT_RE_READING_UNIT           |   190 |  6840 |     5   (0)| 00:00:01 |       |       |
    |  41 |                              TABLE ACCESS FULL     | GCGT_RE_ITINERARY              |   285K|  6689K|  2020   (1)| 00:00:25 |       |       |
    |* 42 |                          INDEX UNIQUE SCAN         | PK_GCGT_RE_ITINERARY_MACRO     |     1 |       |     1   (0)| 00:00:01 |       |       |
    |  43 |                         TABLE ACCESS BY INDEX ROWID| GCGT_RE_ITINERARY_MACRO        |     1 |    62 |     1   (0)| 00:00:01 |       |       |
    |* 44 |                        TABLE ACCESS FULL           | GCGT_RE_ROUTE                  |  5121 |   165K|   358   (1)| 00:00:05 |       |       |
    |* 45 |                       TABLE ACCESS BY INDEX ROWID  | GCGT_RE_MEA_POINT_ROUTE_HIST   |     1 |    29 |     1   (0)| 00:00:01 |       |       |
    |* 46 |                        INDEX RANGE SCAN            | FK_RE_MEA_POINTHIST_ROUTE_01   |     4 |       |     1   (0)| 00:00:01 |       |       |
    |  47 |                      TABLE ACCESS BY INDEX ROWID   | GCGT_RE_MEASUREMENT_POINT      |     1 |    13 |     1   (0)| 00:00:01 |       |       |
    |* 48 |                       INDEX UNIQUE SCAN            | PK_GCGT_RE_MEASUREMENT_POINT   |     1 |       |     1   (0)| 00:00:01 |       |       |
    |* 49 |                     INDEX RANGE SCAN               | IDX_GCGT_RE_MPOINHHIST_04      |     2 |       |     1   (0)| 00:00:01 |       |       |
    |  50 |                    TABLE ACCESS BY INDEX ROWID     | GCGT_RE_MPOINT_HIST            |     2 |    66 |     1   (0)| 00:00:01 |       |       |
    |  51 |                 TABLE ACCESS FULL                  | GCCOM_FARE                     |   374 | 13090 |     6   (0)| 00:00:01 |       |       |
    |  52 |                TABLE ACCESS BY INDEX ROWID         | GCGT_ME_COMBINATION_USAGE_TYPE |    89 |  1335 |     1   (0)| 00:00:01 |       |       |
    |* 53 |                 INDEX RANGE SCAN                   | IDX_FK_ME_COM_US_TY_DEV_TY_01  |    89 |       |     1   (0)| 00:00:01 |       |       |
    |* 54 |               TABLE ACCESS BY GLOBAL INDEX ROWID   | GCGT_RE_READING_E              |     1 |    40 |     1   (0)| 00:00:01 | ROWID | ROWID |
    |* 55 |                INDEX RANGE SCAN                    | IDX$$_00000003                 |     1 |       |     1   (0)| 00:00:01 |       |       |
    |* 56 |              TABLE ACCESS BY INDEX ROWID           | GCGT_ME_MEA_CTYPE_HIST         |     1 |    22 |     1   (0)| 00:00:01 |       |       |
    |* 57 |               INDEX RANGE SCAN                     | IDX_MEA_CTYPE_HIST_01          |     2 |       |     1   (0)| 00:00:01 |       |       |
    |  58 |             TABLE ACCESS BY GLOBAL INDEX ROWID     | GCCOM_SECTOR_SUPPLY            |     1 |    51 |     1   (0)| 00:00:01 | ROWID | ROWID |
    |* 59 |              INDEX RANGE SCAN                      | IDX_GCCOM_SECTOR_SUPPLY_21     |     1 |       |     1   (0)| 00:00:01 |       |       |
    |  60 |            TABLE ACCESS BY GLOBAL INDEX ROWID      | GCCOM_CONTRACTED_SERVICE       |     1 |    35 |     1   (0)| 00:00:01 | ROWID | ROWID |
    |* 61 |             INDEX RANGE SCAN                       | IDX_GCCOMCONTRACTEDSERVICE_28  |     1 |       |     1   (0)| 00:00:01 |       |       |
    |  62 |           TABLE ACCESS BY GLOBAL INDEX ROWID       | GCCOM_CONTRACT                 |     1 |    13 |     1   (0)| 00:00:01 | ROWID | ROWID |
    |* 63 |            INDEX UNIQUE SCAN                       | PK_GCCOM_CONTRACT              |     1 |       |     1   (0)| 00:00:01 |       |       |
    |  64 |          TABLE ACCESS BY INDEX ROWID               | GCGT_ME_MEASURER               |     1 |    16 |     1   (0)| 00:00:01 |       |       |
    |* 65 |           INDEX UNIQUE SCAN                        | PK_GCGT_ME_MEASURER            |     1 |       |     1   (0)| 00:00:01 |       |       |
    |* 66 |         TABLE ACCESS BY INDEX ROWID                | GCGT_ME_DEVICE                 |     1 |    41 |     1   (0)| 00:00:01 |       |       |
    |* 67 |          INDEX UNIQUE SCAN                         | PK_GCGT_ME_DEVICE              |     1 |       |     1   (0)| 00:00:01 |       |       |
    |* 68 |        TABLE ACCESS BY INDEX ROWID                 | GCGT_ME_MEA_POINT_DEVICE_HIST  |     1 |    14 |     1   (0)| 00:00:01 |       |       |
    |* 69 |         INDEX RANGE SCAN                           | IDX_GCGT_ME_MEAPOINTDEVHIST_04 |     1 |       |     1   (0)| 00:00:01 |       |       |
    |  70 |       PARTITION HASH ITERATOR                      |                                |     1 |    33 |     1   (0)| 00:00:01 |   KEY |   KEY |
    |  71 |        TABLE ACCESS BY LOCAL INDEX ROWID           | GCCC_CUSTOMER                  |     1 |    33 |     1   (0)| 00:00:01 |   KEY |   KEY |
    |* 72 |         INDEX UNIQUE SCAN                          | PK_GCCC_CUSTOMER               |     1 |       |     1   (0)| 00:00:01 |   KEY |   KEY |
    |* 73 |      INDEX FULL SCAN                               | PK_GCCOM_COMPANY               |     1 |     5 |     1   (0)| 00:00:01 |       |       |
    |* 74 |     INDEX UNIQUE SCAN                              | PK_GCCOM_COMPANY               |     1 |     5 |     1   (0)| 00:00:01 |       |       |
    |  75 |     SORT AGGREGATE                                 |                                |     1 |    39 |            |          |       |       |
    |* 76 |      TABLE ACCESS BY GLOBAL INDEX ROWID            | GCGT_RE_READING_E              |     1 |    39 |     2   (0)| 00:00:01 | ROWID | ROWID |
    |* 77 |       INDEX RANGE SCAN                             | IDX$$_00000003                 |     1 |       |     1   (0)| 00:00:01 |       |       |
    -----------------------------------------------------------------------------------------------------------------------------------------------------

我改变了这样的子查询:

    SELECT  DISTINCT
        COM_S.COD_USER_COMPANY AS SOCIEDAD,
        COM_D.COD_USER_COMPANY AS DISTRIBUIDORA
    FROM             
        GCCOM_SECTOR_SUPPLY SS 
        LEFT OUTER JOIN GCCOM_COMPANY COM_S ON COM_S.ID_COMPANY = SS.ID_SELLER
        LEFT OUTER JOIN GCCOM_COMPANY COM_D ON COM_D.ID_COMPANY = SS.ID_DISTRIBUTER
        INNER JOIN GCCOM_COMPANY COM ON COM.ID_COMPANY = SS.ID_SELLER OR COM.ID_COMPANY = SS.ID_DISTRIBUTER          
    WHERE  
        3000000 = COM_S.ID_COMPANY
    ORDER BY by SOCIEDAD, DISTRIBUIDORA; 

是不是?返回的行与befora相同。请告诉。

0 个答案:

没有答案