I have 3 tables:
- Table A: 170 million data
- Table B: 170 million data
- Table C: 130 million data
- Table Log
I want to update column colA1 with the value of colC4 if colA2 == colB2 and colB3 == colC3. I created a table:
- Table D: 80 millions data to store colB2 and colC3 in order to speed up the query.
I also add index for colB3 in Table D.
Table Log is used to store progress message and completion time every time an iteration is completed (see the script).
Currently my update script is look like this:
v_str_log := 'Begin updating';
p_write_to_log(v_str_log);
commit;
for data_list in
(
select distinct colC4
from tableC
)
loop
update tableA
set colA1 = data_list.colC4
where colA2 in
(
select colB2
from tableD
where colC3 = data_list.colC4
)
var_total := var_total + sql%rowcount;
v_str_log := 'Updated ' || sql%rowcount || ' for ' || card.sim_type || ' with total ' || var_total || ' rows.';
commit;
end loop;
I have run the procedure and its finished in about 6 hours. But I find from the log, that for the first loop, 3 millions data is executed for 3 minutes, but a few iterations later 5 millions data is executed in about 20 minutes. The query executed not as fast as first iterations
Why could that happened? Can the script be optimized?