I would like to update a column based on joins. Unfortunately, the tables that I am updating and merging are rather large: 87,220,021 rows.
Here is the content of the table (that I am merging with itself):
ID ID_VERSION VALUE_1 VALUE_2 RES_EXPEC
1 1 A NULL NULL
1 2 A NULL 1
1 2 B NULL NULL
1 3 B NULL 1
2 1 A NULL NULL
2 1 B NULL NULL
2 1 B NULL NULL
And here is the code that I am running:
MERGE INTO EXAMP_TAB USING(
SELECT ID, ID_VERSION, VALUE_1 FROM EXAMP_TAB) TAB_B
ON (EXAMP_TAB.ID = TAB_B.ID
AND EXAMP_TAB.ID_VERSION = (TAB_B.ID_VERSION - 1)
AND EXAMP_TAB.VALUE_1 = TAB_B.VALUE_1)
WHEN MATCHED THEN
UPDATE SET EXAMP_TAB.VALUE_2 = 1;
The aim of this operation is to check whether there is an entry with an identical value in VALUE_1 in the previous version of an ID. If so, VALUE_2 is updated.
Unfortunately, this operation takes hours. I read a little bit about indexes but it seems they cannot help me since they do not increase performance on UPDATE-operations.
I am also open to operations that do not involve a Merge-statement.