Currently my query is very heavy, the table (table A) I need to update contains 21 million records
and another table (table B) contains 15 million records. for all the records that are in table B, the records in table A need to be updated.
Using the V$SESSION_LONGOPS I can see that the query is going to take 30 hours to complete. So does anyone know if it’s better to merge & update or just update
below my update query, i already set an index on the join table. this is only a temporary table I created which I will drop after the insert. (not an external table)
UPDATE ITEM_LOC IL
SET
IL.STATUS= 'D' ,
IL.LAST_UPDATE_DATETIME= SYSDATE ,
IL.LAST_UPDATE_ID = 'CNVOBJ_RNG'
where exists
(select il.item, il.loc from item_loc il
join DC_ITEM_LOC DC_IL ON DC_IL.ITEM = IL.ITEM AND DC_IL.LOC = IL.LOC);
This will not do what you expect. This will update every record of
ITEM_LOC(ifITEM_LOCandDC_ITEM_LOChave at least one record in common). Your query is running the full subquery for each row ofITEM_LOC, this is why it takes so long.Your semi-join should be written like this:
Updating a million rows should be a matter of seconds, not hours.