Too long running query - sql

Working on this query to make it faster
I am working on avoiding those TABLE ACCESS FULL and analyze that the right cardinality is applied, but are those the only things that would improve performance ?
Any extra view, would be appreciated.
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;
Explain plan:
I attach herein the explain plan execution, for you to check.
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.
Note the Explain Plan with GATHER_PLAN_STATISTICS, but it seems not to be much difference.
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 | | |
-----------------------------------------------------------------------------------------------------------------------------------------------------
I changed the subqueries like this:
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;
Is it right ? the returned rows is the same than befora. Please tell.

Related

MAX function is causing performance issue in select clause oracle

We have one query which is causing performance issue because of in select cause in case statement.Without that part,full query completing in 20 sec and with this one query took 3 minutes of time.Any way how we can improve the performance of the select below query
(SELECT MAX (ordered_item)
FROM apps.oe_order_lines_all ool, APPS.MTL_SYSTEM_ITEMS_B b
WHERE ool.ato_line_id = oola.line_id
AND ool.inventory_item_id = b.inventory_item_id
AND ool.ship_from_org_id = b.organization_id
AND b.item_type = 'CONFIGURED_ITEM'
AND ool.FLOW_STATUS_CODE <> 'CANCELLED')
As it is self join with ool and if i remove that join it is taking time
> SELECT
> DISTINCT
> hzp.PARTY_NAME,
> CASE
> WHEN b.item_type = 'ATO'
> THEN
> (SELECT MAX (ordered_item)
> FROM apps.oe_order_lines_all ool, APPS.MTL_SYSTEM_ITEMS_B b
> WHERE ool.ato_line_id = oola.line_id
> AND ool.inventory_item_id = b.inventory_item_id
> AND ool.ship_from_org_id = b.organization_id
> AND b.item_type = 'CONFIGURED_ITEM'
> AND ool.FLOW_STATUS_CODE <> 'CANCELLED')
> ELSE
> NULL
> END
> ato_configured_item FROM APPS.OE_ORDER_HEADERS_ALL ooha,
> APPS.OE_ORDER_LINES_ALL oola,
> APPS.MTL_SYSTEM_ITEMS_B b,
> APPS.MTL_PARAMETERS mp,
> APPS.OE_HOLD_DEFINITIONS ohd,
> APPS.OE_HOLD_SOURCES_ALL ohsa,
> APPS.OE_ORDER_HOLDS_ALL ooha1,
> APPS.FND_USER fu,
> APPS.HZ_CUST_SITE_USES_ALL hzcsu,
> APPS.HZ_CUST_ACCT_SITES_ALL hzcas,
> APPS.HZ_CUST_ACCOUNTS hzca,
> APPS.HZ_PARTIES hzp,-----------
> APPS.HZ_PARTY_SITES hzps WHERE ooha.HEADER_ID = oola.HEADER_ID
> AND ooha.ORG_ID = oola.ORG_ID
> AND oola.INVENTORY_ITEM_ID = b.INVENTORY_ITEM_ID
> AND b.ORGANIZATION_ID = mp.ORGANIZATION_ID
> AND oola.SHIP_FROM_ORG_ID = mp.ORGANIZATION_ID
> AND ooha.HEADER_ID = ooha1.HEADER_ID
> AND oola.LINE_ID = ooha1.LINE_ID
> AND ooha1.HOLD_SOURCE_ID = ohsa.HOLD_SOURCE_ID
> AND ohsa.HOLD_ID = ohd.HOLD_ID
> AND b.CREATED_BY = fu.USER_ID
> AND hzcsu.SITE_USE_ID = ooha.INVOICE_TO_ORG_ID
> AND hzcas.CUST_ACCT_SITE_ID = hzcsu.CUST_ACCT_SITE_ID
> AND hzca.CUST_ACCOUNT_ID = hzcas.CUST_ACCOUNT_ID
> AND hzp.PARTY_ID = hzca.PARTY_ID
> AND hzps.PARTY_SITE_ID = hzcas.PARTY_SITE_ID
> AND oola.ITEM_TYPE_CODE IN ('MODEL', 'STANDARD', NULL) --Configured Items and Parts
> AND ooha1.RELEASED_FLAG IN ('N', NULL) --Active holds only
> AND ooha.org_id IN ('1703') --1703 = Valves
> AND oola.FLOW_STATUS_CODE NOT IN ('CLOSED', 'CANCELLED')
> AND ooha.FLOW_STATUS_CODE NOT IN ('CLOSED', 'CANCELLED')
> AND oola.open_flag IN ('Y', NULL)
> AND mp.ORGANIZATION_CODE IN ('FIM'
> )
Execution plan
We have one query which is causing performance issue because of MAX (ordered_item) in select cause in case statement.Without that part query completing in 20 sec and with this one query took 3 minutes of time.Any way to handle this MAX so performance can improve.
------------------------------------------------------------------------------------------------------------------------
| Id | Operation | Name | E-Rows |E-Bytes| Cost (%CPU)| E-Time |
------------------------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | | | 197K(100)| |
| 1 | SORT AGGREGATE | | 1 | 62 | | |
| 2 | NESTED LOOPS | | | | | |
| 3 | NESTED LOOPS | | 42 | 2604 | 145 (0)| 00:00:01 |
|* 4 | TABLE ACCESS BY INDEX ROWID | OE_ORDER_LINES_ALL | 42 | 1722 | 19 (0)| 00:00:01 |
|* 5 | INDEX RANGE SCAN | OE_ORDER_LINES_N17 | 45 | | 4 (0)| 00:00:01 |
|* 6 | INDEX UNIQUE SCAN | MTL_SYSTEM_ITEMS_B_U1 | 1 | | 2 (0)| 00:00:01 |
|* 7 | TABLE ACCESS BY INDEX ROWID | MTL_SYSTEM_ITEMS_B | 1 | 21 | 3 (0)| 00:00:01 |
| 8 | SORT AGGREGATE | | 1 | 210 | | |
| 9 | NESTED LOOPS | | 1 | 210 | 11 (0)| 00:00:01 |
| 10 | NESTED LOOPS | | 1 | 162 | 8 (0)| 00:00:01 |
| 11 | NESTED LOOPS | | 1 | 82 | 6 (0)| 00:00:01 |
| 12 | NESTED LOOPS | | 1 | 41 | 5 (0)| 00:00:01 |
|* 13 | INDEX RANGE SCAN | MTL_ITEM_CATEGORIES_U1 | 1 | 22 | 4 (0)| 00:00:01 |
| 14 | TABLE ACCESS BY INDEX ROWID | MTL_CATEGORY_SETS_B | 1 | 19 | 1 (0)| 00:00:01 |
|* 15 | INDEX UNIQUE SCAN | MTL_CATEGORY_SETS_B_U1 | 1 | | 0 (0)| |
|* 16 | TABLE ACCESS BY INDEX ROWID | MTL_CATEGORY_SETS_TL | 1 | 41 | 1 (0)| 00:00:01 |
|* 17 | INDEX UNIQUE SCAN | MTL_CATEGORY_SETS_TL_U1 | 1 | | 0 (0)| |
|* 18 | TABLE ACCESS BY INDEX ROWID | MTL_CATEGORIES_B | 1 | 80 | 2 (0)| 00:00:01 |
|* 19 | INDEX UNIQUE SCAN | MTL_CATEGORIES_B_U1 | 1 | | 1 (0)| 00:00:01 |
|* 20 | INDEX RANGE SCAN | FND_LOOKUP_VALUES_U1 | 1 | 48 | 3 (0)| 00:00:01 |
| 21 | SORT AGGREGATE | | 1 | 210 | | |
| 22 | NESTED LOOPS | | 1 | 210 | 11 (0)| 00:00:01 |
| 23 | NESTED LOOPS | | 1 | 162 | 8 (0)| 00:00:01 |
| 24 | NESTED LOOPS | | 1 | 82 | 6 (0)| 00:00:01 |
| 25 | NESTED LOOPS | | 1 | 41 | 5 (0)| 00:00:01 |
|* 26 | INDEX RANGE SCAN | MTL_ITEM_CATEGORIES_U1 | 1 | 22 | 4 (0)| 00:00:01 |
| 27 | TABLE ACCESS BY INDEX ROWID | MTL_CATEGORY_SETS_B | 1 | 19 | 1 (0)| 00:00:01 |
|* 28 | INDEX UNIQUE SCAN | MTL_CATEGORY_SETS_B_U1 | 1 | | 0 (0)| |
|* 29 | TABLE ACCESS BY INDEX ROWID | MTL_CATEGORY_SETS_TL | 1 | 41 | 1 (0)| 00:00:01 |
|* 30 | INDEX UNIQUE SCAN | MTL_CATEGORY_SETS_TL_U1 | 1 | | 0 (0)| |
|* 31 | TABLE ACCESS BY INDEX ROWID | MTL_CATEGORIES_B | 1 | 80 | 2 (0)| 00:00:01 |
|* 32 | INDEX UNIQUE SCAN | MTL_CATEGORIES_B_U1 | 1 | | 1 (0)| 00:00:01 |
|* 33 | INDEX RANGE SCAN | FND_LOOKUP_VALUES_U1 | 1 | 48 | 3 (0)| 00:00:01 |
| 34 | SORT AGGREGATE | | 1 | 210 | | |
| 35 | NESTED LOOPS | | 1 | 210 | 11 (0)| 00:00:01 |
| 36 | NESTED LOOPS | | 1 | 162 | 8 (0)| 00:00:01 |
| 37 | NESTED LOOPS | | 1 | 82 | 6 (0)| 00:00:01 |
| 38 | NESTED LOOPS | | 1 | 41 | 5 (0)| 00:00:01 |
|* 39 | INDEX RANGE SCAN | MTL_ITEM_CATEGORIES_U1 | 1 | 22 | 4 (0)| 00:00:01 |
| 40 | TABLE ACCESS BY INDEX ROWID | MTL_CATEGORY_SETS_B | 1 | 19 | 1 (0)| 00:00:01 |
|* 41 | INDEX UNIQUE SCAN | MTL_CATEGORY_SETS_B_U1 | 1 | | 0 (0)| |
|* 42 | TABLE ACCESS BY INDEX ROWID | MTL_CATEGORY_SETS_TL | 1 | 41 | 1 (0)| 00:00:01 |
|* 43 | INDEX UNIQUE SCAN | MTL_CATEGORY_SETS_TL_U1 | 1 | | 0 (0)| |
|* 44 | TABLE ACCESS BY INDEX ROWID | MTL_CATEGORIES_B | 1 | 80 | 2 (0)| 00:00:01 |
|* 45 | INDEX UNIQUE SCAN | MTL_CATEGORIES_B_U1 | 1 | | 1 (0)| 00:00:01 |
|* 46 | INDEX RANGE SCAN | FND_LOOKUP_VALUES_U1 | 1 | 48 | 3 (0)| 00:00:01 |
| 47 | HASH UNIQUE | | 1 | 412 | 197K (1)| 00:00:08 |
| 48 | NESTED LOOPS | | | | | |
| 49 | NESTED LOOPS | | 1 | 412 | 197K (1)| 00:00:08 |
| 50 | NESTED LOOPS | | 1 | 374 | 197K (1)| 00:00:08 |
| 51 | NESTED LOOPS | | 1 | 362 | 197K (1)| 00:00:08 |
| 52 | NESTED LOOPS | | 1 | 356 | 197K (1)| 00:00:08 |
| 53 | NESTED LOOPS | | 1 | 337 | 197K (1)| 00:00:08 |
| 54 | NESTED LOOPS | | 1 | 332 | 197K (1)| 00:00:08 |
| 55 | NESTED LOOPS | | 1 | 287 | 197K (1)| 00:00:08 |
| 56 | NESTED LOOPS | | 1 | 266 | 197K (1)| 00:00:08 |
| 57 | NESTED LOOPS | | 1 | 252 | 197K (1)| 00:00:08 |
| 58 | NESTED LOOPS | | 710 | 159K| 195K (1)| 00:00:08 |
| 59 | NESTED LOOPS | | 710 | 124K| 194K (1)| 00:00:08 |
| 60 | NESTED LOOPS | | 40073 | 4461K| 75450 (1)| 00:00:03 |
|* 61 | TABLE ACCESS FULL | MTL_PARAMETERS | 32 | 288 | 20 (0)| 00:00:01 |
| 62 | INLIST ITERATOR | | | | | |
|* 63 | TABLE ACCESS BY INDEX ROWID| OE_ORDER_LINES_ALL | 1252 | 128K| 3362 (1)| 00:00:01 |
|* 64 | INDEX RANGE SCAN | OE_ORDER_LINES_X101 | 10395 | | 161 (1)| 00:00:01 |
| 65 | TABLE ACCESS BY INDEX ROWID | MTL_SYSTEM_ITEMS_B | 1 | 66 | 3 (0)| 00:00:01 |
|* 66 | INDEX UNIQUE SCAN | MTL_SYSTEM_ITEMS_B_U1 | 1 | | 2 (0)| 00:00:01 |
|* 67 | TABLE ACCESS BY INDEX ROWID | OE_ORDER_HEADERS_ALL | 1 | 50 | 2 (0)| 00:00:01 |
|* 68 | INDEX UNIQUE SCAN | OE_ORDER_HEADERS_U1 | 1 | | 1 (0)| 00:00:01 |
|* 69 | TABLE ACCESS BY INDEX ROWID | OE_ORDER_HOLDS_ALL | 1 | 22 | 6 (0)| 00:00:01 |
|* 70 | INDEX RANGE SCAN | OE_ORDER_HOLDS_ALL_N2 | 3 | | 3 (0)| 00:00:01 |
| 71 | TABLE ACCESS BY INDEX ROWID | HZ_CUST_SITE_USES_ALL | 1 | 14 | 3 (0)| 00:00:01 |
|* 72 | INDEX UNIQUE SCAN | HZ_CUST_SITE_USES_U1 | 1 | | 2 (0)| 00:00:01 |
| 73 | TABLE ACCESS BY INDEX ROWID | OE_HOLD_SOURCES_ALL | 1 | 21 | 3 (0)| 00:00:01 |
|* 74 | INDEX UNIQUE SCAN | OE_HOLD_SOURCES_U1 | 1 | | 2 (0)| 00:00:01 |
|* 75 | TABLE ACCESS BY INDEX ROWID | OE_HOLD_DEFINITIONS | 1 | 45 | 1 (0)| 00:00:01 |
|* 76 | INDEX UNIQUE SCAN | OE_HOLDS_U1 | 1 | | 0 (0)| |
|* 77 | INDEX UNIQUE SCAN | FND_USER_U1 | 1 | 5 | 0 (0)| |
| 78 | TABLE ACCESS BY INDEX ROWID | HZ_CUST_ACCT_SITES_ALL | 1 | 19 | 2 (0)| 00:00:01 |
|* 79 | INDEX UNIQUE SCAN | HZ_CUST_ACCT_SITES_U1 | 1 | | 1 (0)| 00:00:01 |
|* 80 | INDEX UNIQUE SCAN | HZ_PARTY_SITES_U1 | 1 | 6 | 1 (0)| 00:00:01 |
|* 81 | INDEX RANGE SCAN | XXAR_HZ_CUST_ACCOUNTS_N2 | 1 | 12 | 2 (0)| 00:00:01 |
|* 82 | INDEX UNIQUE SCAN | HZ_PARTIES_U1 | 1 | | 1 (0)| 00:00:01 |
| 83 | TABLE ACCESS BY INDEX ROWID | HZ_PARTIES | 1 | 38 | 2 (0)| 00:00:01 |
Why not try something like this:
with ord_items as (
SELECT MAX (ordered_item) moi, ool.ato_line_id
FROM apps.oe_order_lines_all ool, APPS.MTL_SYSTEM_ITEMS_B b
WHERE ool.inventory_item_id = b.inventory_item_id
AND ool.ship_from_org_id = b.organization_id
AND b.item_type = 'CONFIGURED_ITEM'
AND ool.FLOW_STATUS_CODE <> 'CANCELLED'
group by ool.ato_line_id)
SELECT
DISTINCT
hzp.PARTY_NAME,
CASE
WHEN b.item_type = 'ATO'
THEN
(select ois.moi from ord_items ois where ois.ato_line_id = oola.line_id)
ELSE
NULL
END
ato_configured_item FROM ....

Oracle Insert SQL Query Performance Tuning

I have an Insert query which is taking around 5-6 minutes to complete I plan to reduce timing to under 1 minutes.
I see a MERGE JOIN CARTESIAN in the explain plan so looking for ways to avoid it.
Below is concerned query and Explain Plan.
DB : Oracle Database 19c Standard Edition 2 Release 19.0.0.0.0 - Production
INSERT INTO dictdm_discounts_perf
(
DISCOUNT_MIGRATION_ID,
DISCOUNT_NAME,
DISCOUNT_LEVEL,
RBM_PRODUCT_ID,
DISCOUNTED_OFFER_MIGR_ID,
DISCOUNTED_FLAT_OFFER_NAME,
DISCOUNTED_OFFERING_ID,
DISCOUNTED_OFFERING_NAME,
APPLY_MODE,
VALID_TO,
VALID_FROM,
DURATION,
DURATION_UNIT,
PRICE_COMPONENT_SPEC_ID,
PRICE_COMPONENT_SPEC_NAME,
ALT_PRICE,
ABSOLUTE_ALTERATION,
ALTERATION_IN_PERCENT,
TARIFF_ID,
DISCOUNT_RULE,
LEGACY_TARIFF_ID,
DISC_GROUP_ID,
DISC_GROUP_NAME
)
select
dsct.DISCOUNT_ID DISCOUNT_MIGRATION_ID
,dsct.NAME DISCOUNT_NAME
,(select lv.value from nc_list_values lv
where lv.list_value_id = DISCOUNT_LEVEL_VALUE_ID) DISCOUNT_LEVEL
,dsct.DISCOUNT_PRODUCT_ID RBM_PRODUCT_ID
,do.OFFER_MIGRATION_ID DISCOUNTED_OFFER_MIGR_ID
,do.FLAT_OFFERING_NAME DISCOUNTED_FLAT_OFFER_NAME
,do.OFFERING_ID DISCOUNTED_OFFERING_ID
,do.OFFERING_NAME DISCOUNTED_OFFERING_NAME
,(select lv.value from nc_list_values lv where lv.list_value_id = dsct.APPLY_MODE_VALUE_ID) APPLY_MODE
,dsct.AVAILABLE_TO VALID_TO
,dsct.AVAILABLE_FROM VALID_FROM
,dsct.DURATION DURATION
,(select lv.value from nc_list_values lv where lv.list_value_id = dsct.DURATION_UNIT_VALUE_ID) DURATION_UNIT
,pa.PRICE_SPEC_ID PRICE_COMPONENT_SPEC_ID
,(select o.name from nc_objects o where o.object_id = pa.PRICE_SPEC_ID) PRICE_COMPONENT_SPEC_NAME
,pa.PRICE_ALTERATION_ID ALT_PRICE
,decode(pa.DISC_AMOUNT_TYPE_VALUE_ID,9154646390213102438/*Absolute*/,pa.DISCOUNT_AMOUNT,null) ABSOLUTE_ALTERATION
,decode(pa.DISC_AMOUNT_TYPE_VALUE_ID,9154646390213102439/*Percentage*/,pa.DISCOUNT_AMOUNT,null) ALTERATION_IN_PERCENT
,pp.EXTERNAL_PRICE_PLAN_ID TARIFF_ID
,rl.RULE_ID DISCOUNT_RULE
,dsct.LEGACY_TARIFF_ID LEGACY_TARIFF_ID
,PD.DISCOUNT_GROUP_ID DISC_GROUP_ID
,O.NAME DISC_GROUP_NAME
from
POC_DISCOUNT dsct
join POC_DISCOUNT_TO_OBJECT d2o on d2o.DISCOUNT_ID = dsct.DISCOUNT_ID
join DICTDM_OFFERINGS do on decode(d2o.TYPE_ID,
9155001372713095116/*Offering*/, do.OFFERING_ID,
9155431485713090836/*Falt Offering*/, do.OFFER_MIGRATION_ID) = d2o.OBJECT_ID
or (d2o.TYPE_ID = 9155001372713095117/*Category*/ and instr(do.OFFERING_CATEGORY_ID,d2o.OBJECT_ID)>0)
left join POC_PRICE_ALTERATION pa on pa.DISCOUNT_ID = dsct.DISCOUNT_ID
left join PRICE_PLAN pp on pp.FLAT_OBJECT_ID = dsct.DISCOUNT_ID and pp.DISCOUNTED_OFFERING_ID = do.OFFERING_ID
left join POC_DISCOUNT_TO_RULE rl on rl.DISCOUNT_ID = dsct.DISCOUNT_ID
left join POC_DISCOUNT_TO_GROUP PD ON dsct.DISCOUNT_ID=PD.DISCOUNT_ID
left join NC_OBJECTS O ON O.OBJECT_ID=PD.DISCOUNT_GROUP_ID
where not exists (
select 0 from nc_params ofst
where ofst.object_id = do.offering_id
and ofst.attr_id = 7021759771013444983 /*Status*/
and ofst.list_value_id = 9140545748713273967 /*Discontinued*/
);
Plan hash value: 3564192537
------------------------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
------------------------------------------------------------------------------------------------------------------------
| 0 | INSERT STATEMENT | | 10987 | 5203K| 4703 (1)| 00:00:01 |
| 1 | LOAD TABLE CONVENTIONAL | DICTDM_DISCOUNTS | | | | |
| 2 | TABLE ACCESS BY INDEX ROWID | NC_LIST_VALUES | 1 | 23 | 1 (0)| 00:00:01 |
|* 3 | INDEX UNIQUE SCAN | XPKNC_LIST_VALUES | 1 | | 1 (0)| 00:00:01 |
| 4 | TABLE ACCESS BY INDEX ROWID | NC_LIST_VALUES | 1 | 23 | 1 (0)| 00:00:01 |
|* 5 | INDEX UNIQUE SCAN | XPKNC_LIST_VALUES | 1 | | 1 (0)| 00:00:01 |
| 6 | TABLE ACCESS BY INDEX ROWID | NC_LIST_VALUES | 1 | 23 | 1 (0)| 00:00:01 |
|* 7 | INDEX UNIQUE SCAN | XPKNC_LIST_VALUES | 1 | | 1 (0)| 00:00:01 |
| 8 | TABLE ACCESS BY INDEX ROWID | NC_OBJECTS | 1 | 32 | 1 (0)| 00:00:01 |
|* 9 | INDEX UNIQUE SCAN | XPKNC_OBJECTS | 1 | | 1 (0)| 00:00:01 |
|* 10 | HASH JOIN RIGHT OUTER | | 10987 | 5203K| 4696 (1)| 00:00:01 |
| 11 | TABLE ACCESS FULL | POC_PRICE_ALTERATION | 48 | 2160 | 3 (0)| 00:00:01 |
|* 12 | HASH JOIN RIGHT OUTER | | 9613 | 4130K| 4693 (1)| 00:00:01 |
| 13 | INDEX FULL SCAN | PK_POC_DISCOUNT_TO_RULE | 9 | 81 | 1 (0)| 00:00:01 |
| 14 | NESTED LOOPS OUTER | | 9176 | 3862K| 4692 (1)| 00:00:01 |
| 15 | NESTED LOOPS OUTER | | 9176 | 3575K| 4691 (1)| 00:00:01 |
|* 16 | HASH JOIN RIGHT OUTER | | 9176 | 3342K| 4690 (1)| 00:00:01 |
| 17 | TABLE ACCESS FULL | PRICE_PLAN | 1 | 39 | 3 (0)| 00:00:01 |
|* 18 | HASH JOIN | | 9176 | 2992K| 4687 (1)| 00:00:01 |
| 19 | TABLE ACCESS FULL | POC_DISCOUNT_TO_OBJECT | 43 | 1032 | 3 (0)| 00:00:01 |
| 20 | MERGE JOIN CARTESIAN | | 132K| 39M| 4683 (1)| 00:00:01 |
| 21 | NESTED LOOPS ANTI | | 3167 | 451K| 385 (0)| 00:00:01 |
| 22 | TABLE ACCESS FULL | DICTDM_OFFERINGS | 5660 | 608K| 102 (0)| 00:00:01 |
|* 23 | TABLE ACCESS BY INDEX ROWID BATCHED| NC_PARAMS | 44 | 1584 | 1 (0)| 00:00:01 |
|* 24 | INDEX RANGE SCAN | XIF12NC_PARAMS | 1 | | 1 (0)| 00:00:01 |
| 25 | BUFFER SORT | | 42 | 6888 | 4682 (1)| 00:00:01 |
| 26 | TABLE ACCESS FULL | POC_DISCOUNT | 42 | 6888 | 1 (0)| 00:00:01 |
| 27 | TABLE ACCESS BY INDEX ROWID BATCHED | POC_DISCOUNT_TO_GROUP | 1 | 26 | 1 (0)| 00:00:01 |
|* 28 | INDEX RANGE SCAN | IDX_DISCOUNT_TO_GROUP_D | 1 | | 1 (0)| 00:00:01 |
| 29 | TABLE ACCESS BY INDEX ROWID | NC_OBJECTS | 1 | 32 | 1 (0)| 00:00:01 |
|* 30 | INDEX UNIQUE SCAN | XPKNC_OBJECTS | 1 | | 1 (0)| 00:00:01 |
------------------------------------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
3 - access("LV"."LIST_VALUE_ID"=:B1)
5 - access("LV"."LIST_VALUE_ID"=:B1)
7 - access("LV"."LIST_VALUE_ID"=:B1)
9 - access("O"."OBJECT_ID"=:B1)
10 - access("PA"."DISCOUNT_ID"(+)="DSCT"."DISCOUNT_ID")
12 - access("RL"."DISCOUNT_ID"(+)="DSCT"."DISCOUNT_ID")
16 - access("PP"."DISCOUNTED_OFFERING_ID"(+)="DO"."OFFERING_ID" AND
"PP"."FLAT_OBJECT_ID"(+)="DSCT"."DISCOUNT_ID")
18 - access("D2O"."DISCOUNT_ID"="DSCT"."DISCOUNT_ID")
filter("D2O"."OBJECT_ID"=DECODE("D2O"."TYPE_ID",9155001372713095116,"DO"."OFFERING_ID",915543148571309083
6,"DO"."OFFER_MIGRATION_ID") OR "D2O"."TYPE_ID"=9155001372713095117 AND
INSTR("DO"."OFFERING_CATEGORY_ID",TO_CHAR("D2O"."OBJECT_ID"))>0)
23 - filter("OFST"."LIST_VALUE_ID"=9140545748713273967)
24 - access("OFST"."OBJECT_ID"="DO"."OFFERING_ID" AND "OFST"."ATTR_ID"=7021759771013444983)
28 - access("DSCT"."DISCOUNT_ID"="PD"."DISCOUNT_ID"(+))
30 - access("O"."OBJECT_ID"(+)="PD"."DISCOUNT_GROUP_ID")

Adding Explain Plans together from a split SQL Query

We have a procedure that uses a huge SQL Query to retrieve information, then insert it into a another table XX_REP_TABLE. The SQL query is below:
SELECT
xx_det.ledger_id,
<< ... more where clauses ... >>
nvl(xx_line.tax_calculation_formula, 'STANDARD_TC') tax_line_user_attribute14,
CASE
WHEN COUNT(*) OVER(PARTITION BY xxx_rcpt_line.accounting_class_code, xxx_rcpt_dist.source_distribution_id_num_1, xxx_rcpt_dist.
event_id) = 1 THEN
NULL
WHEN ( ( xxx_rcpt_line.overridden_code_combination_id IS NULL
AND xxx_rcpt_line.override_reason IS NOT NULL )
OR ( EXISTS (
SELECT
'Reversal of original due to override exists'
FROM
xxx_ae_lines xal2,
xxx_distribution_links xdl2
WHERE
xdl2.application_id = 999
AND xal2.application_id = 999
AND xal2.ae_header_id = xdl2.ae_header_id
AND xal2.ae_line_num = xdl2.ae_line_num
AND xal2.overridden_code_combination_id IS NULL
AND xal2.override_reason IS NOT NULL
AND xdl2.source_distribution_type = 'xx_DISTRIBUTIONS_ALL'
AND xal2.ledger_id = xxx_rcpt_line.ledger_id
AND xdl2.source_distribution_id_num_1 = xxx_rcpt_dist.source_distribution_id_num_1
AND xdl2.ref_ae_header_id = xxx_rcpt_dist.ae_header_id
AND xdl2.ref_ae_line_num = xxx_rcpt_dist.ae_line_num
) ) ) THEN
'DEL'
ELSE
NULL
END tax_line_user_attribute15
<< ... more where clauses ... >>
FROM
xx_lines_det_factors xx_det,
xx_lines xx_line,
xx_exemptions xx_ex,
xx_taxes_b xx_tax,
xx_accounts xx_accounts,
xx_rates_vl xx_rate,
xxx_events xxx_event,
xxx_ae_headers xxx_head,
xxx_ae_lines xxx_line,
xxx_acct_class_assgns acs,
xxx_assignment_defns_b asd,
xxx_distribution_links xxx_dist,
xx_receivable_applications_all ara,
xxx_events xxx_rcpt_event,
xxx_ae_headers xxx_rcpt_head,
xxx_ae_lines xxx_rcpt_line,
xxx_distribution_links xxx_rcpt_dist,
xx_distributions_all ardist,
xx_cust_trx_line_gl_dist_all trx_dist,
xx_customer_trx_lines_all lines
WHERE
xx_det.tax_reporting_flag = 'Y'
<< ... more where clauses ... >>
AND 1 = 1;
The Explain plan is below:
---------------------------------------------------------------------------------------------------------------------------------------------------------------
| Id | exeOrd| Operation | Name | Rows | Bytes |TempSpc| Cost (%CPU)| Time |
---------------------------------------------------------------------------------------------------------------------------------------------------------------
| 0 | 66 | SELECT STATEMENT | | | | | 283K(100)| |
| 1 | 65 | NESTED LOOPS SEMI | | 1 | 319 | | 7 (0)| 00:00:01 |
| 2 | 62 | TABLE ACCESS BY INDEX ROWID BATCHED | xxx_distribution_links | 1 | 50 | | 5 (0)| 00:00:01 |
| 3 | 61 | INDEX RANGE SCAN | xxx_distribution_links_N1 | 2 | | | 4 (0)| 00:00:01 |
| 4 | 64 | TABLE ACCESS BY INDEX ROWID | xxx_ae_lines | 1 | 269 | | 2 (0)| 00:00:01 |
| 5 | 63 | INDEX UNIQUE SCAN | xxx_ae_lines_U1 | 1 | | | 1 (0)| 00:00:01 |
| 6 | 60 | WINDOW SORT | | 1 | 2792 | | 283K (1)| 00:00:12 |
| 7 | 59 | FILTER | | | | | | |
| 8 | 58 | NESTED LOOPS OUTER | | 1 | 2792 | | 283K (1)| 00:00:12 |
| 9 | 56 | NESTED LOOPS | | 1 | 2753 | | 283K (1)| 00:00:12 |
| 10 | 53 | NESTED LOOPS | | 1 | 2743 | | 283K (1)| 00:00:12 |
| 11 | 50 | NESTED LOOPS | | 1 | 2723 | | 283K (1)| 00:00:12 |
| 12 | 47 | NESTED LOOPS | | 1 | 2696 | | 283K (1)| 00:00:12 |
| 13 | 44 | NESTED LOOPS | | 1 | 2654 | | 283K (1)| 00:00:12 |
| 14 | 41 | HASH JOIN | | 1 | 2630 | | 283K (1)| 00:00:12 |
| 15 | 39 | NESTED LOOPS | | 1 | 2585 | | 232K (1)| 00:00:10 |
| 16 | 36 | NESTED LOOPS | | 1 | 2493 | | 232K (1)| 00:00:10 |
| 17 | 33 | NESTED LOOPS | | 15 | 36750 | | 232K (1)| 00:00:10 |
| 18 | 30 | HASH JOIN | | 2455 | 3735K| | 225K (1)| 00:00:09 |
| 19 | 1 | TABLE ACCESS STORAGE FULL | xx_rates_tl | 82 | 8938 | | 5 (0)| 00:00:01 |
| 20 | 29 | HASH JOIN | | 2455 | 3473K| | 225K (1)| 00:00:09 |
| 21 | 2 | TABLE ACCESS STORAGE FULL | xx_rates_b | 82 | 6970 | | 3 (0)| 00:00:01 |
| 22 | 28 | HASH JOIN | | 2455 | 3270K| | 225K (1)| 00:00:09 |
| 23 | 3 | TABLE ACCESS STORAGE FULL | xx_rates_b | 21 | 546 | | 5 (0)| 00:00:01 |
| 24 | 27 | NESTED LOOPS | | 2455 | 3207K| | 225K (1)| 00:00:09 |
| 25 | 25 | NESTED LOOPS | | 9516 | 3207K| | 225K (1)| 00:00:09 |
| 26 | 23 | HASH JOIN | | 2379 | 1119K| 8072K| 218K (1)| 00:00:09 |
| 27 | 20 | JOIN FILTER CREATE | :BF0000 | 2379 | 1119K| | 218K (1)| 00:00:09 |
| 28 | 19 | HASH JOIN | | 18159 | 7855K| 7680K| 190K (1)| 00:00:08 |
| 29 | 16 | JOIN FILTER CREATE | :BF0001 | 18159 | 7855K| | 190K (1)| 00:00:08 |
| 30 | 15 | HASH JOIN | | 18159 | 7465K| 7112K| 168K (1)| 00:00:07 |
| 31 | 12 | JOIN FILTER CREATE | :BF0002 | 18159 | 6898K| | 115K (1)| 00:00:05 |
| 32 | 11 | MERGE JOIN CARTESIAN | | 18159 | 6898K| | 115K (1)| 00:00:05 |
| 33 | 7 | NESTED LOOPS | | 1 | 120 | | 2 (0)| 00:00:01 |
| 34 | 5 | TABLE ACCESS BY INDEX ROWID | xxx_assignment_defns_b | 1 | 53 | | 2 (0)| 00:00:01 |
| 35 | 4 | INDEX SKIP SCAN | xxx_assignment_defns_b_U1 | 1 | | | 1 (0)| 00:00:01 |
| 36 | 6 | INDEX UNIQUE SCAN | xxx_ACCT_CLASS_ASSGNS_U1 | 1 | 67 | | 0 (0)| |
| 37 | 10 | BUFFER SORT | | 329K| 84M| | 115K (1)| 00:00:05 |
| 38 | 9 | TABLE ACCESS BY INDEX ROWID BATCHED| xxx_ae_lines | 329K| 84M| | 115K (1)| 00:00:05 |
| 39 | 8 | INDEX RANGE SCAN | xxx_ae_lines_N2 | 2084K| | | 6741 (1)| 00:00:01 |
| 40 | 14 | JOIN FILTER USE | :BF0002 | 844K| 25M| | 50709 (1)| 00:00:02 |
| 41 | 13 | TABLE ACCESS STORAGE FULL | xxx_ae_headers | 844K| 25M| | 50709 (1)| 00:00:02 |
| 42 | 18 | JOIN FILTER USE | :BF0001 | 2526K| 53M| | 18048 (1)| 00:00:01 |
| 43 | 17 | TABLE ACCESS STORAGE FULL | xxx_events | 2526K| 53M| | 18048 (1)| 00:00:01 |
| 44 | 22 | JOIN FILTER USE | :BF0000 | 319K| 11M| | 27552 (1)| 00:00:02 |
| 45 | 21 | TABLE ACCESS STORAGE FULL | xx_receivable_applications_all | 319K| 11M| | 27552 (1)| 00:00:02 |
| 46 | 24 | INDEX RANGE SCAN | xx_LINES_N4 | 4 | | | 2 (0)| 00:00:01 |
| 47 | 26 | TABLE ACCESS BY INDEX ROWID | xx_lines | 1 | 856 | | 3 (0)| 00:00:01 |
| 48 | 32 | TABLE ACCESS BY INDEX ROWID BATCHED | xx_lines_det_factors | 1 | 892 | | 3 (0)| 00:00:01 |
| 49 | 31 | INDEX RANGE SCAN | xx_LINES_DET_FACTORS_N2 | 3 | | | 2 (0)| 00:00:01 |
| 50 | 35 | TABLE ACCESS BY INDEX ROWID BATCHED | xx_distributions_all | 1 | 43 | | 3 (0)| 00:00:01 |
| 51 | 34 | INDEX RANGE SCAN | xx_DISTRIBUTIONS_N1 | 1 | | | 2 (0)| 00:00:01 |
| 52 | 38 | TABLE ACCESS BY INDEX ROWID BATCHED | xxx_distribution_links | 1 | 92 | | 3 (0)| 00:00:01 |
| 53 | 37 | INDEX RANGE SCAN | xxx_distribution_links_N3 | 1 | | | 2 (0)| 00:00:01 |
| 54 | 40 | TABLE ACCESS STORAGE FULL | xxx_ae_headers | 26278 | 1154K| | 50711 (1)| 00:00:02 |
| 55 | 43 | TABLE ACCESS BY INDEX ROWID BATCHED | xxx_ae_lines | 1 | 24 | | 3 (0)| 00:00:01 |
| 56 | 42 | INDEX RANGE SCAN | xxx_ae_lines_U1 | 1 | | | 2 (0)| 00:00:01 |
| 57 | 46 | TABLE ACCESS BY INDEX ROWID BATCHED | xxx_distribution_links | 1 | 42 | | 3 (0)| 00:00:01 |
| 58 | 45 | INDEX RANGE SCAN | xxx_distribution_links_N3 | 1 | | | 2 (0)| 00:00:01 |
| 59 | 49 | TABLE ACCESS BY INDEX ROWID | xx_cust_trx_line_gl_dist_all | 1 | 27 | | 2 (0)| 00:00:01 |
| 60 | 48 | INDEX UNIQUE SCAN | xx_CUST_TRX_LINE_GL_DIST_U1 | 1 | | | 1 (0)| 00:00:01 |
| 61 | 52 | TABLE ACCESS BY INDEX ROWID | xx_customer_trx_lines_all | 1 | 20 | | 2 (0)| 00:00:01 |
| 62 | 51 | INDEX UNIQUE SCAN | xx_CUSTOMER_TRX_LINES_U1 | 1 | | | 1 (0)| 00:00:01 |
| 63 | 55 | TABLE ACCESS BY INDEX ROWID BATCHED | xxx_events | 1 | 10 | | 3 (0)| 00:00:01 |
| 64 | 54 | INDEX RANGE SCAN | xxx_EVENTS_U1 | 1 | | | 2 (0)| 00:00:01 |
| 65 | 57 | INDEX UNIQUE SCAN | xx_ACCOUNTS_U2 | 1 | 39 | | 0 (0)| |
---------------------------------------------------------------------------------------------------------------------------------------------------------------
Based on some of our analysis, this is caused by a COUNT(*) OVER(PARTITION BY in the SELECTed columns. When i remove that Analytic Function, the explain plan removes the Full Table Scans:
-------------------------------------------------------------------------------------------------------------------------------------------------
| Id | exeOrd| Operation | Name | E-Rows |E-Bytes| Cost (%CPU)| E-Time |
-------------------------------------------------------------------------------------------------------------------------------------------------
| 0 | 55 | SELECT STATEMENT | | | | 504K(100)| |
| 1 | 54 | NESTED LOOPS | | 1 | 2537 | 504K (1)| 00:00:20 |
| 2 | 51 | NESTED LOOPS | | 1 | 2517 | 504K (1)| 00:00:20 |
| 3 | 48 | NESTED LOOPS | | 1 | 2490 | 504K (1)| 00:00:20 |
| 4 | 45 | NESTED LOOPS | | 1 | 2448 | 504K (1)| 00:00:20 |
| 5 | 42 | NESTED LOOPS | | 1 | 2422 | 504K (1)| 00:00:20 |
| 6 | 39 | NESTED LOOPS | | 1 | 1523 | 504K (1)| 00:00:20 |
| 7 | 36 | NESTED LOOPS | | 9 | 13383 | 504K (1)| 00:00:20 |
| 8 | 33 | NESTED LOOPS | | 9 | 13293 | 504K (1)| 00:00:20 |
|* 9 | 30 | HASH JOIN | | 392 | 546K| 504K (1)| 00:00:20 |
| 10 | 27 | NESTED LOOPS | | 1 | 1403 | 340K (1)| 00:00:14 |
| 11 | 24 | NESTED LOOPS | | 1 | 1381 | 340K (1)| 00:00:14 |
|* 12 | 21 | HASH JOIN | | 1 | 1271 | 340K (1)| 00:00:14 |
| 13 | 19 | NESTED LOOPS | | 1 | 1186 | 340K (1)| 00:00:14 |
| 14 | 16 | NESTED LOOPS | | 2752 | 857K| 333K (1)| 00:00:14 |
| 15 | 13 | NESTED LOOPS | | 12119 | 3313K| 311K (1)| 00:00:13 |
| 16 | 10 | NESTED LOOPS | | 28044 | 6490K| 254K (1)| 00:00:10 |
| 17 | 7 | NESTED LOOPS | | 22839 | 3234K| 163K (1)| 00:00:07 |
| 18 | 4 | NESTED LOOPS | | 1 | 120 | 2 (0)| 00:00:01 |
|* 19 | 2 | TABLE ACCESS BY INDEX ROWID BATCHED| xla_assignment_defns_b | 1 | 53 | 2 (0)| 00:00:01 |
|* 20 | 1 | INDEX SKIP SCAN | XLA_ASSIGNMENT_DEFNS_B_U1 | 1 | | 1 (0)| 00:00:01 |
|* 21 | 3 | INDEX UNIQUE SCAN | XLA_ACCT_CLASS_ASSGNS_U1 | 1 | 67 | 0 (0)| |
|* 22 | 6 | TABLE ACCESS BY INDEX ROWID BATCHED | xla_ae_lines | 414K| 9M| 163K (1)| 00:00:07 |
|* 23 | 5 | INDEX RANGE SCAN | XLA_AE_LINES_N2 | 2824K| | 9684 (1)| 00:00:01 |
|* 24 | 9 | TABLE ACCESS BY INDEX ROWID BATCHED | xla_distribution_links | 1 | 92 | 4 (0)| 00:00:01 |
|* 25 | 8 | INDEX RANGE SCAN | XLA_DISTRIBUTION_LINKS_N3 | 1 | | 3 (0)| 00:00:01 |
|* 26 | 12 | TABLE ACCESS BY INDEX ROWID | ar_distributions_all | 1 | 43 | 2 (0)| 00:00:01 |
|* 27 | 11 | INDEX UNIQUE SCAN | AR_DISTRIBUTIONS_U2 | 1 | | 1 (0)| 00:00:01 |
|* 28 | 15 | TABLE ACCESS BY INDEX ROWID | ar_receivable_applications_all | 1 | 39 | 2 (0)| 00:00:01 |
|* 29 | 14 | INDEX UNIQUE SCAN | AR_RECEIVABLE_APPLICATIONS_U1 | 1 | | 1 (0)| 00:00:01 |
|* 30 | 18 | TABLE ACCESS BY INDEX ROWID BATCHED | zx_lines | 1 | 867 | 3 (0)| 00:00:01 |
|* 31 | 17 | INDEX RANGE SCAN | ZX_LINES_N4 | 4 | | 2 (0)| 00:00:01 |
| 32 | 20 | TABLE ACCESS STORAGE FULL | zx_rates_b | 1 | 85 | 1 (0)| 00:00:01 |
| 33 | 23 | TABLE ACCESS BY INDEX ROWID | zx_rates_tl | 1 | 110 | 1 (0)| 00:00:01 |
|* 34 | 22 | INDEX UNIQUE SCAN | ZX_RATES_TL_U1 | 1 | | 0 (0)| |
|* 35 | 26 | TABLE ACCESS BY INDEX ROWID BATCHED | xla_events | 1 | 22 | 3 (0)| 00:00:01 |
|* 36 | 25 | INDEX RANGE SCAN | XLA_EVENTS_U1 | 1 | | 2 (0)| 00:00:01 |
|* 37 | 29 | TABLE ACCESS BY INDEX ROWID BATCHED | xla_ae_lines | 414K| 9M| 163K (1)| 00:00:07 |
|* 38 | 28 | INDEX RANGE SCAN | XLA_AE_LINES_N2 | 2824K| | 9685 (1)| 00:00:01 |
|* 39 | 32 | TABLE ACCESS BY INDEX ROWID | xla_ae_headers | 1 | 49 | 2 (0)| 00:00:01 |
|* 40 | 31 | INDEX UNIQUE SCAN | XLA_AE_HEADERS_U1 | 1 | | 1 (0)| 00:00:01 |
|* 41 | 35 | TABLE ACCESS BY INDEX ROWID BATCHED | xla_events | 1 | 10 | 3 (0)| 00:00:01 |
|* 42 | 34 | INDEX RANGE SCAN | XLA_EVENTS_U1 | 1 | | 2 (0)| 00:00:01 |
|* 43 | 38 | TABLE ACCESS BY INDEX ROWID | xla_ae_headers | 1 | 36 | 2 (0)| 00:00:01 |
|* 44 | 37 | INDEX UNIQUE SCAN | XLA_AE_HEADERS_U1 | 1 | | 1 (0)| 00:00:01 |
|* 45 | 41 | TABLE ACCESS BY INDEX ROWID BATCHED | zx_lines_det_factors | 1 | 899 | 3 (0)| 00:00:01 |
|* 46 | 40 | INDEX RANGE SCAN | ZX_LINES_DET_FACTORS_N2 | 3 | | 2 (0)| 00:00:01 |
| 47 | 44 | TABLE ACCESS BY INDEX ROWID | zx_taxes_b | 1 | 26 | 1 (0)| 00:00:01 |
|* 48 | 43 | INDEX UNIQUE SCAN | ZX_TAXES_B_U1 | 1 | | 0 (0)| |
|* 49 | 47 | TABLE ACCESS BY INDEX ROWID BATCHED | xla_distribution_links | 1 | 42 | 4 (0)| 00:00:01 |
|* 50 | 46 | INDEX RANGE SCAN | XLA_DISTRIBUTION_LINKS_N3 | 1 | | 3 (0)| 00:00:01 |
|* 51 | 50 | TABLE ACCESS BY INDEX ROWID | ra_cust_trx_line_gl_dist_all | 1 | 27 | 2 (0)| 00:00:01 |
|* 52 | 49 | INDEX UNIQUE SCAN | RA_CUST_TRX_LINE_GL_DIST_U1 | 1 | | 1 (0)| 00:00:01 |
|* 53 | 53 | TABLE ACCESS BY INDEX ROWID | ra_customer_trx_lines_all | 1 | 20 | 2 (0)| 00:00:01 |
|* 54 | 52 | INDEX UNIQUE SCAN | RA_CUSTOMER_TRX_LINES_U1 | 1 | | 1 (0)| 00:00:01 |
-------------------------------------------------------------------------------------------------------------------------------------------------
I plan to move that Analytic function to a separate Procedure, similar to something like below (not yet the exact procedure):
procedure Identify_duplicates (p_request_id number)
as
cursor cur_duplicate_information (p_request_id number)
is
SELECT
REP_TBL_ID, -- UNIQUE IDENTIFIER
CASE
WHEN COUNT(*) OVER(PARTITION BY xxrtbl.accounting_class_code, xxrtbl.source_distribution_id_num_1, xxrtbl.event_id) = 1 THEN
NULL
WHEN ( ( xxx_rcpt_line.overridden_code_combination_id IS NULL
AND xxx_rcpt_line.override_reason IS NOT NULL )
OR ( EXISTS (
SELECT
'Reversal of original due to override exists'
FROM
xxx_ae_lines xal2,
xxx_distribution_links xdl2
WHERE
xdl2.application_id = 999
AND xal2.application_id = 999
AND xal2.ae_header_id = xdl2.ae_header_id
AND xal2.ae_line_num = xdl2.ae_line_num
AND xal2.overridden_code_combination_id IS NULL
AND xal2.override_reason IS NOT NULL
AND xdl2.source_distribution_type = 'xx_DISTRIBUTIONS_ALL'
AND xal2.ledger_id = xxrtbl.ledger_id
AND xdl2.source_distribution_id_num_1 = xxrtbl.source_distribution_id_num_1
AND xdl2.ref_ae_header_id = xxrtbl.ae_header_id
AND xdl2.ref_ae_line_num = xxrtbl.ae_line_num
) ) ) THEN
'DEL'
ELSE
NULL
END tax_line_user_attribute15
FROM XX_REP_TABLE xxrtbl
WHERE REQ_ID = p_request_id;
type typ_dup_info cur_duplicate_information%type;
rec_dup_info typ_dup_info;
begin
OPEN cur_duplicate_information;
FETCH cur_duplicate_information
BULK COLLECT
INTO rec_dup_info
CLOSE cur_duplicate_information;
forall rec_dup_info.first .. rec_dup_info.last
UPDATE XX_REP_TABLE
SET tax_line_user_attribute15 = rec_dup_info(i).tax_line_user_attribute15
where REP_TBL_ID = REP_TBL_ID(i).REP_TBL_ID;
exception
when others then
dbms_output.put_line('Error in :'||SQLERRM);
raise;
end;
I am curious to find out if this will make any difference.
Will "adding" the two explain plans provide a rough estimate of the total cost?
Note: i cannot run this from our own instances because there is too few records to have an actual impact. This performance issue was from our customer and they have billions of records, which we cannot export or mimic. Hence, I wanted to "theoretically" calculate it first before making the code fix.
This query
SELECT a, b, COUNT(*) OVER (PARTITION BY b)
FROM table
gives similar results to
SELECT t.a, t.b, q.number
FROM table t
JOIN ( SELECT b, COUNT(*) number
FROM table
GROUP BY b
) q ON t.b = q.b
The subquery in the second item can exploit an index on b.
Without seeing your entire query, it's hard to guess how to refactor it to use such a subquery.
And, by the way, as long as you're working on that chunk of code, you should consider bringing it into the 1990s by using explicit JOINs. Instead of this
SELECT ...
FROM t1, t2, t3
WHERE t1.t1_id = t2.t1_id
AND t2.t2_id = t3.t2_id(+)
Use this
SELECT ...
FROM t1
INNER JOIN t2 ON t1.t1_id = t2.t1_id
LEFT JOIN t3 ON t2.t2_id = t3.t2_id
The comma-join syntax was replaced by explicit joins in SQL-92, a generation ago.

Function-Based-Index when using IN subquery

I'm have the following code
WITH T AS(
SELECT SOMETHING
)
SELECT * FROM tab1 t1
LEFT JOIN tab2 t2 on t1.ID = t2 .ID
LEFT JOIN tab3 t3 on t1.ID = t3 .ID
LEFT JOIN tab4 t4 on t1.ID = t4.ID
LEFT JOIN tab5 t5 on t1.ID = t5.ID
INNER JOIN tempo_tab6 t6 on t1.ID = t6.ID
LEFT JOIN tab7 t7 on t1.ID = t7.ID
WHERE t1.Col1 = 0
AND t1.Col2 = 1
AND t1.Col3 IN (SELECT t8.Col FROM tab8 t8 WHERE Col ='ABC')
When I execute the Advisor, It advised me create FBI in ID.Col3, but my company rule isn't accept FBI In any case. Is there any way to solve this? It took 18s for some values without Index.
Many thanks.
Edit: this is the execution plan of this case.
PLAN_TABLE_OUTPUT
-----------------------------------------------------------------------------------------------------------------------------------
Plan hash value: 1976489795
-----------------------------------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-----------------------------------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 873 | 11730 (1)| 00:00:01 |
| 1 | TEMP TABLE TRANSFORMATION | | | | | |
| 2 | LOAD AS SELECT | SYS_TEMP_1FD9EE041_D91A3E0 | | | | |
| 3 | HASH UNIQUE | | 1 | 436 | 15 (7)| 00:00:01 |
| 4 | MERGE JOIN CARTESIAN | | 1 | 436 | 14 (0)| 00:00:01 |
|* 5 | HASH JOIN OUTER | | 1 | 436 | 5 (0)| 00:00:01 |
PLAN_TABLE_OUTPUT
-----------------------------------------------------------------------------------------------------------------------------------
| 6 | NESTED LOOPS | | 1 | 220 | 3 (0)| 00:00:01 |
| 7 | NESTED LOOPS | | 1 | 217 | 3 (0)| 00:00:01 |
| 8 | NESTED LOOPS | | 1 | 209 | 2 (0)| 00:00:01 |
|* 9 | TABLE ACCESS FULL | TMP_REPORT | 1 | 204 | 2 (0)| 00:00:01 |
|* 10 | INDEX UNIQUE SCAN | PK_STOCK_ID | 1 | 5 | 0 (0)| 00:00:01 |
|* 11 | INDEX RANGE SCAN | IX_LS_STOCK_ZONE_FK_STOCK_ID_FK_ZONE_ID | 1 | 8 | 1 (0)| 00:00:01 |
|* 12 | INDEX UNIQUE SCAN | PK_ZONE_ID | 1 | 3 | 0 (0)| 00:00:01 |
|* 13 | TABLE ACCESS FULL | TMP_REPORT | 1 | 216 | 2 (0)| 00:00:01 |
| 14 | BUFFER SORT | | 12727 | | 12 (0)| 00:00:01 |
| 15 | INDEX FAST FULL SCAN | PK_STOCK_DEPARTMENT_ID | 12727 | | 9 (0)| 00:00:01 |
| 16 | COUNT | | | | | |
PLAN_TABLE_OUTPUT
-----------------------------------------------------------------------------------------------------------------------------------
|* 17 | HASH JOIN SEMI | | 1 | 873 | 11715 (1)| 00:00:01 |
| 18 | MERGE JOIN OUTER | | 1 | 669 | 11713 (1)| 00:00:01 |
| 19 | NESTED LOOPS OUTER | | 1 | 354 | 11709 (1)| 00:00:01 |
| 20 | NESTED LOOPS OUTER | | 1 | 284 | 11708 (1)| 00:00:01 |
| 21 | NESTED LOOPS OUTER | | 1 | 264 | 11707 (1)| 00:00:01 |
| 22 | NESTED LOOPS OUTER | | 1 | 237 | 11706 (1)| 00:00:01 |
| 23 | NESTED LOOPS OUTER | | 1 | 180 | 11705 (1)| 00:00:01 |
| 24 | NESTED LOOPS OUTER | | 1 | 166 | 11704 (1)| 00:00:01 |
| 25 | NESTED LOOPS OUTER | | 1 | 141 | 11703 (1)| 00:00:01 |
| 26 | NESTED LOOPS OUTER | | 1 | 123 | 11702 (1)| 00:00:01 |
|* 27 | HASH JOIN | | 1 | 100 | 11701 (1)| 00:00:01 |
PLAN_TABLE_OUTPUT
-----------------------------------------------------------------------------------------------------------------------------------
| 28 | VIEW | | 1 | 26 | 2 (0)| 00:00:01 |
| 29 | TABLE ACCESS FULL | SYS_TEMP_1FD9EE041_D91A3E0 | 1 | 18 | 2 (0)| 00:00:01 |
|* 30 | TABLE ACCESS FULL | LS_ITEM_DETAILS | 870K| 61M| 11696 (1)| 00:00:01 |
| 31 | TABLE ACCESS BY INDEX ROWID| LS_ZONES | 1 | 23 | 1 (0)| 00:00:01 |
|* 32 | INDEX UNIQUE SCAN | PK_ZONE_ID | 1 | | 0 (0)| 00:00:01 |
| 33 | TABLE ACCESS BY INDEX ROWID | LS_INCIDENTS | 1 | 18 | 1 (0)| 00:00:01 |
|* 34 | INDEX UNIQUE SCAN | PK_INCIDENT_ID | 1 | | 0 (0)| 00:00:01 |
| 35 | TABLE ACCESS BY INDEX ROWID | LS_EMPLOYEES | 1 | 25 | 1 (0)| 00:00:01 |
|* 36 | INDEX UNIQUE SCAN | PK_EMPLOYEE_ID | 1 | | 0 (0)| 00:00:01 |
| 37 | TABLE ACCESS BY INDEX ROWID | LS_PROJECTS | 1 | 14 | 1 (0)| 00:00:01 |
|* 38 | INDEX UNIQUE SCAN | PK_PROJECT_ID | 1 | | 0 (0)| 00:00:01 |
PLAN_TABLE_OUTPUT
-----------------------------------------------------------------------------------------------------------------------------------
| 39 | TABLE ACCESS BY INDEX ROWID | LS_STOCKS | 1 | 57 | 1 (0)| 00:00:01 |
|* 40 | INDEX UNIQUE SCAN | PK_STOCK_ID | 1 | | 0 (0)| 00:00:01 |
| 41 | TABLE ACCESS BY INDEX ROWID | LS_PLANS | 1 | 27 | 1 (0)| 00:00:01 |
|* 42 | INDEX UNIQUE SCAN | PK_PLAN_ID | 1 | | 0 (0)| 00:00:01 |
| 43 | TABLE ACCESS BY INDEX ROWID | LS_GROUPS | 1 | 20 | 1 (0)| 00:00:01 |
|* 44 | INDEX UNIQUE SCAN | PK_GROUP_ID | 1 | | 0 (0)| 00:00:01 |
| 45 | TABLE ACCESS BY INDEX ROWID | LS_ITEMS | 1 | 70 | 1 (0)| 00:00:01 |
|* 46 | INDEX UNIQUE SCAN | ITEM_CODE_UNI | 1 | | 0 (0)| 00:00:01 |
| 47 | BUFFER SORT | | 2 | 630 | 11712 (1)| 00:00:01 |
| 48 | VIEW | VW_LAT_B17BD126 | 2 | 630 | 4 (0)| 00:00:01 |
| 49 | VIEW | VW_ORE_F374A3FE | 2 | 630 | 4 (0)| 00:00:01 |
PLAN_TABLE_OUTPUT
-----------------------------------------------------------------------------------------------------------------------------------
| 50 | UNION-ALL | | | | | |
|* 51 | FILTER | | | | | |
| 52 | TABLE ACCESS BY INDEX ROWID | LS_SUPPLIERS | 1 | 51 | 2 (0)| 00:00:01 |
|* 53 | INDEX UNIQUE SCAN | PK_SUPPLIER_ID | 1 | | 1 (0)| 00:00:01 |
|* 54 | FILTER | | | | | |
| 55 | TABLE ACCESS BY INDEX ROWID | LS_SUPPLIERS | 1 | 51 | 2 (0)| 00:00:01 |
|* 56 | INDEX UNIQUE SCAN | PK_SUPPLIER_ID | 1 | | 1 (0)| 00:00:01 |
|* 57 | TABLE ACCESS FULL | TMP_REPORT | 1 | 204 | 2 (0)| 00:00:01 |
-----------------------------------------------------------------------------------------------------------------------------------
The advisor suggest me create this FBI:
create index ISCHN.IDX$$_25380001 on ISCHN.LS_ITEM_DETAILS(SYS_OP_C2C("SERIAL"));

Pushing predicate in a view

The scenerio
explain plan for
select l.etl_id , v.*
from v_load_base v, etl_log l
where l.is_active = 1
and v.ddate between trunc(l.load_from_date) and l.load_to_date
and v.starttime_full between l.load_from_date and l.load_to_date;
Produces this execution plan
--------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes |TempSpc| Cost (%CPU)| Time |
--------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 3 | 444 | | 31624 (4)| 00:06:20 |
| 1 | SORT ORDER BY | | 3 | 444 | | 31624 (4)| 00:06:20 |
|* 2 | HASH JOIN | | 3 | 444 | | 31623 (4)| 00:06:20 |
| 3 | NESTED LOOPS OUTER | | 3 | 378 | | 31413 (4)| 00:06:17 |
|* 4 | HASH JOIN | | 3 | 348 | | 31410 (4)| 00:06:17 |
|* 5 | HASH JOIN | | 1252 | 118K| 2144K| 23428 (4)| 00:04:42 |
|* 6 | HASH JOIN | | 27786 | 1818K| | 764 (7)| 00:00:10 |
| 7 | NESTED LOOPS | | 8 | 264 | | 7 (0)| 00:00:01 |
|* 8 | TABLE ACCESS FULL | ETL_LOG | 1 | 21 | | 3 (0)| 00:00:01 |
|* 9 | TABLE ACCESS FULL | MD | 8 | 96 | | 4 (0)| 00:00:01 |
| 10 | TABLE ACCESS FULL | DS | 479K| 15M| | 748 (6)| 00:00:09 |
| 11 | TABLE ACCESS FULL | MDS | 7280K| 208M| | 7823 (5)| 00:01:34 |
| 12 | TABLE ACCESS FULL | TASKS | 7760K| 140M| | 7844 (5)| 00:01:35 |
| 13 | TABLE ACCESS BY INDEX ROWID| ETL_GIS | 1 | 10 | | 1 (0)| 00:00:01 |
|* 14 | INDEX UNIQUE SCAN | ETL_GIS_UK | 1 | | | 0 (0)| 00:00:01 |
| 15 | TABLE ACCESS FULL | DETAILS_TABLE | 292K| 6280K| | 204 (8)| 00:00:03 |
--------------------------------------------------------------------------------------------------------
The join predicate with the table etl_log was pushed down to the view v_load_base (line 8).
I created a view called v_load_base_active based on the same exact query as the one above.
Querying the new view produces the following plan
explain plan for select * from v_load_base_active;
----------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes |TempSpc| Cost (%CPU)| Time |
----------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 3 | 861 | | 63583 (8)| 00:12:43 |
| 1 | NESTED LOOPS | | 3 | 861 | | 63583 (8)| 00:12:43 |
|* 2 | TABLE ACCESS FULL | ETL_LOG | 1 | 21 | | 3 (0)| 00:00:01 |
|* 3 | VIEW | V_LOAD_BASE | 3 | 798 | | 63580 (8)| 00:12:43 |
| 4 | SORT ORDER BY | | 422K| 51M| 110M| 63580 (8)| 00:12:43 |
|* 5 | HASH JOIN RIGHT OUTER | | 422K| 51M| | 51513 (9)| 00:10:19 |
| 6 | TABLE ACCESS FULL | ETL_GIS | 5958 | 59580 | | 17 (0)| 00:00:01 |
|* 7 | HASH JOIN | | 422K| 47M| 9712K| 51488 (9)| 00:10:18 |
| 8 | TABLE ACCESS FULL | LINES_DETAILS | 292K| 6280K| | 204 (8)| 00:00:03 |
|* 9 | HASH JOIN | | 422K| 38M| 35M| 48647 (10)| 00:09:44 |
|* 10 | HASH JOIN | | 422K| 30M| | 27365 (14)| 00:05:29 |
| 11 | TABLE ACCESS FULL | MD | 3103 | 37236 | | 4 (0)| 00:00:01 |
|* 12 | HASH JOIN | | 7301K| 445M| 21M| 24366 (3)| 00:04:53 |
| 13 | TABLE ACCESS FULL| DS | 479K| 15M| | 748 (6)| 00:00:09 |
| 14 | TABLE ACCESS FULL| MSD | 7280K| 208M| | 7823 (5)| 00:01:34 |
| 15 | TABLE ACCESS FULL | TASKS | 7760K| 140M| | 7844 (5)| 00:01:35 |
----------------------------------------------------------------------------------------------------
The predicate is not pushed. This leads to a major decrease in performance.
I've tried setting a hint explicitly in the view /*+ PUSH_PRED(v) */ but the plan does not change.
How can i make the optimizer push the predicate also within a view ... ?
v_load_base does not contain analytic functions. The first query proves that the predicate can be pushed.
EDIT
notice that oracle does not state in the execution plan that a predicate was pushed with VIEW PUSHED PREDICATE. but, looking at the plan it's clear that oracle transformed the view's sql to include the etl_log predicate.
I doubt that it was pushing predicate in the first case, because it would be in the plan. More likely it was merging which is controlled by MERGE/NO_MERGE hints. See example below.
With NO_MERGE:
SQL> explain plan for
2 select /*+NO_MERGE(so)*/ *
3 from siebel.s_org_ext soe,
4 (select sx.attrib_08, s.*
5 from siebel.s_opty s
6 inner join siebel.s_opty_x sx on s.row_id = sx.row_id) so
7 where soe.row_id = so.pr_dept_ou_id
8 and soe.row_id like '1-8ZT%'
9 and so.db_last_upd between soe.db_last_upd and soe.db_last_upd - 365;
Explained
SQL> select * from table(dbms_xplan.display);
Plan hash value: 1802470607
---------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
---------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 13258 | 55 (2)| 00:00:01 |
|* 1 | HASH JOIN | | 1 | 13258 | 55 (2)| 00:00:01 |
| 2 | TABLE ACCESS BY INDEX ROWID| S_ORG_EXT | 1 | 1047 | 3 (0)| 00:00:01 |
|* 3 | INDEX RANGE SCAN | S_ORG_EXT_P1 | 1 | | 2 (0)| 00:00:01 |
| 4 | VIEW | | 1084 | 12M| 52 (2)| 00:00:01 |
|* 5 | HASH JOIN | | 1084 | 528K| 52 (2)| 00:00:01 |
| 6 | TABLE ACCESS FULL | S_OPTY_X | 1573 | 15730 | 17 (0)| 00:00:01 |
|* 7 | TABLE ACCESS FULL | S_OPTY | 1084 | 517K| 34 (0)| 00:00:01 |
---------------------------------------------------------------------------------------------
With MERGE:
SQL> explain plan for
2 select /*+MERGE(so)*/*
3 from siebel.s_org_ext soe,
4 (select sx.attrib_08, s.*
5 from siebel.s_opty s
6 inner join siebel.s_opty_x sx on s.row_id = sx.row_id) so
7 where soe.row_id = so.pr_dept_ou_id
8 and soe.row_id like '1-8ZT%'
9 and so.db_last_upd between soe.db_last_upd and soe.db_last_upd - 365;
Explained
SQL> select * from table(dbms_xplan.display);
Plan hash value: 4111959163
----------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
----------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 1546 | 6 (0)| 00:00:01 |
| 1 | NESTED LOOPS | | 1 | 1546 | 6 (0)| 00:00:01 |
| 2 | NESTED LOOPS | | 1 | 1536 | 5 (0)| 00:00:01 |
| 3 | TABLE ACCESS BY INDEX ROWID| S_ORG_EXT | 1 | 1047 | 3 (0)| 00:00:01 |
|* 4 | INDEX RANGE SCAN | S_ORG_EXT_P1 | 1 | | 2 (0)| 00:00:01 |
|* 5 | TABLE ACCESS BY INDEX ROWID| S_OPTY | 1 | 489 | 2 (0)| 00:00:01 |
|* 6 | INDEX RANGE SCAN | S_OPTY_M64_X | 1 | | 1 (0)| 00:00:01 |
| 7 | TABLE ACCESS BY INDEX ROWID | S_OPTY_X | 1 | 10 | 1 (0)| 00:00:01 |
|* 8 | INDEX UNIQUE SCAN | S_OPTY_X_P1 | 1 | | 0 (0)| 00:00:01 |
----------------------------------------------------------------------------------------------
So try to force optimizer use merging with you view and see if plan changes.