Hi Friends,
I have two tables with following data.
CS_DS_DETAIL : 15.8 Million Rows
SALES_DATA : 28.05 Millions Rows
When I execute the following MERGE statement it completed only 1% after 8 hours.
SQL> explain plan for
2 MERGE /*+ INDEX(dtl cs_ds_detail_pk,sd sales_data_pk) */ INTO sales_data sd
3 USING cs_ds_detail dtl
4 ON ( sd.item_id = dtl.item_id
5 AND sd.location_id = dtl.location_id
6 AND sd.sales_date = dtl.week_end_date)
7 WHEN MATCHED THEN
8 UPDATE
9 SET sd.cs_turn_ord = dtl.turn_plug_adj, sd.cs_promo_ord = dtl.promo_plug;
Explained.
SQL> SELECT *
2 FROM TABLE(DBMS_XPLAN.DISPLAY);
PLAN_TABLE_OUTPUT
----------------------------------------------------------------------------------------------------
Plan hash value: 3300673510
----------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes |TempSpc| Cost (%CPU)| Time |
----------------------------------------------------------------------------------------------------
| 0 | MERGE STATEMENT | | 15M| 457M| | 2615K (2)| 08:43:12 |
| 1 | MERGE | SALES_DATA | | | | | |
| 2 | VIEW | | | | | | |
|* 3 | HASH JOIN | | 15M| 4279M| 897M| 2615K (2)| 08:43:12 |
| 4 | TABLE ACCESS BY INDEX ROWID| CS_DS_DETAIL | 15M| 723M| | 1319K (1)| 04:23:52 |
| 5 | INDEX FULL SCAN | CS_DS_DETAIL_PK | 15M| | | 80488 (1)| 00:16:06 |
PLAN_TABLE_OUTPUT
----------------------------------------------------------------------------------------------------
| 6 | TABLE ACCESS FULL | SALES_DATA | 26M| 6178M| | 929K (4)| 03:05:56 |
----------------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
3 - access("SD"."ITEM_ID"="DTL"."ITEM_ID" AND "SD"."LOCATION_ID"="DTL"."LOCATION_ID" AND
"SD"."SALES_DATE"="DTL"."WEEK_END_DATE")
How can I make it work better. It is a straight forward Merge statement and we are using Oracle 11g.
Both the tables are not partitioned.
Is there a way I can write this using simple Update rather using Merge?
Does anyone think Update has better performance than Merge in this case ?
Thanks guys for your time.
~Raj