Oracle SQL Update Query, looping to limit rows updated at a time -
i have query updates past history new column. pulls values source table corresponding id. compares update time current time, may change guarantees run on every row.
update table1 set table1.comment = (select table2.comment table2 table1.id = table2.id) where(select table2.updatetime table2 table1.id = table2.id) < sysdate
there millions of rows in production , need limit in loop or update many @ time. new sql , have not been able find documentation on how loop limit amount of rows updated. how loop know rows in tables being used?
a couple of things... first, if tables have primary keys, preferred update methodology:
update ( select t1.comment c1, t2.comment c2 table1 t1, table2 t2 t1.id = t2.id , t2.updatetime < sysdate ) set c1 = c2
second, assuming updatetime means think means, wouldn't less sysdate? there reason this?
third, minimize number of unnecessary updates, think add this. assuming percentage of rows require update, should dramatically impact performance.
update ( select t1.comment c1, t2.comment c2 table1 t1, table2 t2 t1.id = t2.id , t2.updatetime < sysdate , ((t1.comment null , t2.comment not null) or (t1.comment not null , t2.comment null) or t1.comment != t2.comment) ) set c1 = c2
finally, i'm not saying loop never help, saying it's wrong approach. oracle tuned sort of thing. if update query slow, it's doubtful wrapping in procedural loop make run faster. updating millions of rows should not issue tuned oracle database.
i understand thought behind doing this, , makes sense in human world. i've tried myself have wise oracle man tell me wrong. when tuned update query, turns out quite right.
Comments
Post a Comment