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 ....
Related
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")
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.
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"));
I have two views, v_movimiento_no_duplicado and v_personas_no_duplicadas. Both queries removes duplicates from tables CLM020A and CLM010A respectively. When i execute each query individually i get fast return, when i join them is fast too. Problem is when i put some predicates, for example:
SELECT *
FROM v_movimiento_no_duplicado
INNER JOIN v_personas_no_duplicadas USING (cedula_rel)
WHERE LENGTH (nombres_010) <= 30
AND LENGTH (apellidos_010) <= 30
--AND LENGTH (cedula_rel) <= 15;
Without last predicate takes 125 ms(is ok),but if add third predicate takes 11 seconds. I haven't indexes at this moment, but i have tried indexes for each of three colums, composites indexes even function-based indexes, but result is the same or worst. This are the plans for both cases:
With two predicates (faster):
-------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 27 | 7371 | 253 (2)| 00:00:04 |
|* 1 | HASH JOIN | | 27 | 7371 | 253 (2)| 00:00:04 |
|* 2 | HASH JOIN | | 27 | 7047 | 149 (3)| 00:00:02 |
|* 3 | HASH JOIN SEMI | | 14 | 1596 | 46 (5)| 00:00:01 |
| 4 | JOIN FILTER CREATE | :BF0000 | 14 | 1148 | 22 (0)| 00:00:01 |
|* 5 | TABLE ACCESS FULL | CLM010A | 14 | 1148 | 22 (0)| 00:00:01 |
| 6 | VIEW | VW_NSO_1 | 56 | 1792 | 23 (5)| 00:00:01 |
|* 7 | FILTER | | | | | |
| 8 | HASH GROUP BY | | 1 | 672 | 23 (5)| 00:00:01 |
| 9 | JOIN FILTER USE | :BF0000 | 5532 | 66384 | 22 (0)| 00:00:01 |
|* 10 | TABLE ACCESS FULL| CLM010A | 5532 | 66384 | 22 (0)| 00:00:01 |
| 11 | TABLE ACCESS FULL | CLM020A | 10734 | 1540K| 102 (0)| 00:00:02 |
| 12 | VIEW | VW_NSO_2 | 10734 | 125K| 104 (2)| 00:00:02 |
| 13 | HASH GROUP BY | | 10734 | 461K| 104 (2)| 00:00:02 |
|* 14 | TABLE ACCESS FULL | CLM020A | 10734 | 461K| 102 (0)| 00:00:02 |
-------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - access("M".ROWID="FILA")
2 - access("CEDULA_REL"="CEDULA_REL")
3 - access("CEDULA_REL"="CEDULA_REL")
5 - filter(LENGTH("NOMBRES_010")<=30 AND LENGTH("APELLIDOS_010")<=30)
7 - filter(COUNT("CEDULA_REL")=1)
10 - filter(SYS_OP_BLOOM_FILTER(:BF0000,"CEDULA_REL"))
14 - filter(("M"."TIPO_020"='E' OR "M"."TIPO_020"='S') AND
"M"."LUGARMOV_020" IS NOT NULL)
Now, with three predicates (slower):
--------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 229 | 252 (2)| 00:00:04 |
|* 1 | FILTER | | | | | |
|* 2 | HASH JOIN | | 1 | 229 | 125 (1)| 00:00:02 |
|* 3 | TABLE ACCESS FULL | CLM010A | 1 | 82 | 22 (0)| 00:00:01 |
| 4 | TABLE ACCESS FULL | CLM020A | 10734 | 1540K| 102 (0)| 00:00:02 |
|* 5 | FILTER | | | | | |
| 6 | HASH GROUP BY | | 1 | 12 | 23 (5)| 00:00:01 |
| 7 | TABLE ACCESS FULL| CLM010A | 5532 | 66384 | 22 (0)| 00:00:01 |
|* 8 | FILTER | | | | | |
| 9 | HASH GROUP BY | | 108 | 4752 | 104 (2)| 00:00:02 |
|* 10 | TABLE ACCESS FULL| CLM020A | 10734 | 461K| 102 (0)| 00:00:02 |
--------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter( EXISTS (SELECT 0 FROM "LIMOV"."CLM010A" "P2" GROUP BY
"CEDULA_REL" HAVING "CEDULA_REL"=:B1 AND COUNT("CEDULA_REL")=1) AND
EXISTS (SELECT 0 FROM "LIMOV"."CLM020A" "M" WHERE ("M"."TIPO_020"='E'
OR "M"."TIPO_020"='S') AND "M"."LUGARMOV_020" IS NOT NULL GROUP BY
UPPER(TRIM("M"."LUGARMOV_020"))||UPPER("M"."TIPO_020")||TO_CHAR(INTERNAL
_FUNCTION("M"."FECHA_020"),'YYYYMMDDHH24MI')||"M"."CEDULA_REL" HAVING
MAX("M".ROWID)=:B2))
2 - access("CEDULA_REL"="CEDULA_REL")
3 - filter(LENGTH("NOMBRES_010")<=30 AND LENGTH("APELLIDOS_010")<=30
AND LENGTH("CEDULA_REL")<=15)
5 - filter("CEDULA_REL"=:B1 AND COUNT("CEDULA_REL")=1)
8 - filter(MAX("M".ROWID)=:B1)
10 - filter(("M"."TIPO_020"='E' OR "M"."TIPO_020"='S') AND
"M"."LUGARMOV_020" IS NOT NULL)
As you can see both plans are differents. I haven't much experience working with plans, any help will be appreciated.
--VIEWS
CREATE VIEW V_MOVIMIENTO_NO_DUPLICADO SELECT "CEDULA_REL",
"TIPO_020",
"FECHA_020",
"LUGARMOV_020",
"CLM_020",
"TRASLADO_020",
"RESPALDADO",
"ESTADIA",
"DIRECCION",
"FECHA_LETRA",
"HORA_SERVER",
"USUARIO"
FROM movimiento m
WHERE m.ROWID IN ( SELECT MAX (m.ROWID) fila
FROM movimiento m
WHERE M.lugarmov_020 IS NOT NULL
AND M.tipo_020 IN ('E', 'S')
GROUP BY UPPER (TRIM (M.lugarmov_020))
|| UPPER (M.tipo_020)
|| TO_CHAR (M.fecha_020, 'YYYYMMDDHH24MI')
|| M.CEDULA_REL)
CREATE VIEW V_PERSONAS_NO_DUPLICADAS SELECT CEDULA_REL,
NOMBRES_010,
APELLIDOS_010,
FECHANAC_010,
NACIONALIDAD_010,
TVIAJERO_010,
RESPALDADO,
RESIDENCIA,
SEXO,
FREGISTRO,
PC,
USUARIO,
USERUPDATE,
DATEUPDATE
FROM persona P1
WHERE cedula_rel IN ( SELECT cedula_rel
FROM persona P2
GROUP BY cedula_rel
HAVING COUNT (cedula_rel) = 1)
--Plans after indexes were added:
Fastest Query: (taking 12 secs more)
---------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
---------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 261 | 133 (4)| 00:00:02 |
| 1 | NESTED LOOPS | | | | | |
| 2 | NESTED LOOPS | | 1 | 261 | 29 (7)| 00:00:01 |
| 3 | NESTED LOOPS | | 1 | 114 | 26 (8)| 00:00:01 |
| 4 | VIEW | VW_NSO_1 | 56 | 1792 | 23 (5)| 00:00:01 |
|* 5 | FILTER | | | | | |
| 6 | HASH GROUP BY | | 1 | 672 | 23 (5)| 00:00:01 |
| 7 | TABLE ACCESS FULL | CLM010A | 5532 | 66384 | 22 (0)| 00:00:01 |
|* 8 | TABLE ACCESS BY INDEX ROWID| CLM010A | 1 | 82 | 2 (0)| 00:00:01 |
|* 9 | INDEX RANGE SCAN | IDX_CEDULA_REL | 1 | | 1 (0)| 00:00:01 |
|* 10 | INDEX RANGE SCAN | IDX_CEDULA_REL_2 | 2 | | 1 (0)| 00:00:01 |
|* 11 | FILTER | | | | | |
| 12 | HASH GROUP BY | | 108 | 4752 | 104 (2)| 00:00:02 |
|* 13 | TABLE ACCESS FULL | CLM020A | 10734 | 461K| 102 (0)| 00:00:02 |
| 14 | TABLE ACCESS BY INDEX ROWID | CLM020A | 1 | 147 | 3 (0)| 00:00:01 |
---------------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
5 - filter(COUNT("CEDULA_REL")=1)
8 - filter(LENGTH("NOMBRES_010")<=30)
9 - access("CEDULA_REL"="CEDULA_REL")
filter(LENGTH("CEDULA_REL")<=15)
10 - access("CEDULA_REL"="CEDULA_REL")
filter( EXISTS (SELECT 0 FROM "LIMOV"."CLM020A" "M" WHERE ("M"."TIPO_020"='E' OR
"M"."TIPO_020"='S') AND "M"."LUGARMOV_020" IS NOT NULL GROUP BY
UPPER(TRIM("M"."LUGARMOV_020"))||UPPER("M"."TIPO_020")||TO_CHAR(INTERNAL_FUNCTION("M"."FECH
A_020"),'YYYYMMDDHH24MI')||"M"."CEDULA_REL" HAVING MAX("M".ROWID)=:B1))
11 - filter(MAX("M".ROWID)=:B1)
13 - filter(("M"."TIPO_020"='E' OR "M"."TIPO_020"='S') AND "M"."LUGARMOV_020" IS NOT
NULL)
Slowest Query:(canceled at 2 mins)
-----------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-----------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 241 | 116 (3)| 00:00:02 |
|* 1 | FILTER | | | | | |
| 2 | HASH GROUP BY | | 1 | 241 | 116 (3)| 00:00:02 |
| 3 | NESTED LOOPS | | | | | |
| 4 | NESTED LOOPS | | 1 | 241 | 11 (0)| 00:00:01 |
| 5 | NESTED LOOPS | | 1 | 94 | 8 (0)| 00:00:01 |
|* 6 | TABLE ACCESS BY INDEX ROWID| CLM010A | 1 | 82 | 7 (0)| 00:00:01 |
|* 7 | INDEX RANGE SCAN | IDX_CEDULA_LEN | 50 | | 2 (0)| 00:00:01 |
|* 8 | INDEX RANGE SCAN | IDX_CEDULA_REL | 1 | 12 | 1 (0)| 00:00:01 |
|* 9 | INDEX RANGE SCAN | IDX_CEDULA_REL_2 | 2 | | 1 (0)| 00:00:01 |
|* 10 | FILTER | | | | | |
| 11 | HASH GROUP BY | | 108 | 4752 | 104 (2)| 00:00:02 |
|* 12 | TABLE ACCESS FULL | CLM020A | 10734 | 461K| 102 (0)| 00:00:02 |
| 13 | TABLE ACCESS BY INDEX ROWID | CLM020A | 1 | 147 | 3 (0)| 00:00:01 |
-----------------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter(COUNT("CEDULA_REL")=1)
6 - filter(LENGTH("NOMBRES_010")<=30 AND LENGTH("APELLIDOS_010")<=30)
7 - access(LENGTH("CEDULA_REL")<=15)
8 - access("CEDULA_REL"="CEDULA_REL")
9 - access("CEDULA_REL"="CEDULA_REL")
filter( EXISTS (SELECT 0 FROM "LIMOV"."CLM020A" "M" WHERE ("M"."TIPO_020"='E' OR
"M"."TIPO_020"='S') AND "M"."LUGARMOV_020" IS NOT NULL GROUP BY
UPPER(TRIM("M"."LUGARMOV_020"))||UPPER("M"."TIPO_020")||TO_CHAR(INTERNAL_FUNCTION("M"."FECHA_
020"),'YYYYMMDDHH24MI')||"M"."CEDULA_REL" HAVING MAX("M".ROWID)=:B1))
10 - filter(MAX("M".ROWID)=:B1)
12 - filter(("M"."TIPO_020"='E' OR "M"."TIPO_020"='S') AND "M"."LUGARMOV_020" IS NOT NULL)
I solved the problem changing the order of the views in the join, then the execution plan changes, and filters changes drastically.
Slowest query:
SELECT *
FROM v_movimiento_no_duplicado
INNER JOIN v_personas_no_duplicadas USING (cedula_rel)
WHERE LENGTH (nombres_010) <= 30
AND LENGTH (apellidos_010) <= 30
AND LENGTH (cedula_rel) <= 15;
--------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 229 | 252 (2)| 00:00:04 |
|* 1 | FILTER | | | | | |
|* 2 | HASH JOIN | | 1 | 229 | 125 (1)| 00:00:02 |
|* 3 | TABLE ACCESS FULL | CLM010A | 1 | 82 | 22 (0)| 00:00:01 |
| 4 | TABLE ACCESS FULL | CLM020A | 10734 | 1540K| 102 (0)| 00:00:02 |
|* 5 | FILTER | | | | | |
| 6 | HASH GROUP BY | | 1 | 12 | 23 (5)| 00:00:01 |
| 7 | TABLE ACCESS FULL| CLM010A | 5532 | 66384 | 22 (0)| 00:00:01 |
|* 8 | FILTER | | | | | |
| 9 | HASH GROUP BY | | 108 | 4752 | 104 (2)| 00:00:02 |
|* 10 | TABLE ACCESS FULL| CLM020A | 10734 | 461K| 102 (0)| 00:00:02 |
--------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter( EXISTS (SELECT 0 FROM "LIMOV"."CLM010A" "P2" GROUP BY
"CEDULA_REL" HAVING "CEDULA_REL"=:B1 AND COUNT("CEDULA_REL")=1) AND
EXISTS (SELECT 0 FROM "LIMOV"."CLM020A" "M" WHERE ("M"."TIPO_020"='E'
OR "M"."TIPO_020"='S') AND "M"."LUGARMOV_020" IS NOT NULL GROUP BY
UPPER(TRIM("M"."LUGARMOV_020"))||UPPER("M"."TIPO_020")||TO_CHAR(INTERNAL
_FUNCTION("M"."FECHA_020"),'YYYYMMDDHH24MI')||"M"."CEDULA_REL" HAVING
MAX("M".ROWID)=:B2))
2 - access("CEDULA_REL"="CEDULA_REL")
3 - filter(LENGTH("NOMBRES_010")<=30 AND LENGTH("APELLIDOS_010")<=30
AND LENGTH("CEDULA_REL")<=15)
5 - filter("CEDULA_REL"=:B1 AND COUNT("CEDULA_REL")=1)
8 - filter(MAX("M".ROWID)=:B1)
10 - filter(("M"."TIPO_020"='E' OR "M"."TIPO_020"='S') AND
"M"."LUGARMOV_020" IS NOT NULL)
Check that filter 1 looks to be a bit expensive. When i changed the order of views it just disappear.
SELECT *
FROM v_personas_no_duplicadas
INNER JOIN v_movimiento_no_duplicado USING (cedula_rel)
WHERE LENGTH (nombres_010) <= 30
AND LENGTH (apellidos_010) <= 30
AND LENGTH (cedula_rel) <= 15;
----------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
----------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 14 | 3822 | 253 (2)| 00:00:04 |
|* 1 | HASH JOIN SEMI | | 14 | 3822 | 253 (2)| 00:00:04 |
|* 2 | HASH JOIN | | 14 | 3374 | 229 (2)| 00:00:03 |
|* 3 | HASH JOIN | | 14 | 3206 | 125 (1)| 00:00:02 |
|* 4 | TABLE ACCESS FULL | CLM010A | 14 | 1148 | 22 (0)| 00:00:01 |
|* 5 | TABLE ACCESS FULL | CLM020A | 537 | 78939 | 102 (0)| 00:00:02 |
| 6 | VIEW | VW_NSO_1 | 10734 | 125K| 104 (2)| 00:00:02 |
| 7 | HASH GROUP BY | | 10734 | 461K| 104 (2)| 00:00:02 |
|* 8 | TABLE ACCESS FULL| CLM020A | 10734 | 461K| 102 (0)| 00:00:02 |
| 9 | VIEW | VW_NSO_2 | 56 | 1792 | 23 (5)| 00:00:01 |
|* 10 | FILTER | | | | | |
| 11 | HASH GROUP BY | | 1 | 672 | 23 (5)| 00:00:01 |
| 12 | TABLE ACCESS FULL| CLM010A | 5532 | 66384 | 22 (0)| 00:00:01 |
----------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - access("CEDULA_REL"="CEDULA_REL")
2 - access("M".ROWID="FILA")
3 - access("CEDULA_REL"="CEDULA_REL")
4 - filter(LENGTH("NOMBRES_010")<=30 AND LENGTH("APELLIDOS_010")<=30)
5 - filter(LENGTH("CEDULA_REL")<=15)
8 - filter(("M"."TIPO_020"='E' OR "M"."TIPO_020"='S') AND
"M"."LUGARMOV_020" IS NOT NULL)
10 - filter(COUNT("CEDULA_REL")=1)
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.