Frequent commits are widely understood to negatively impact performance. Thus, committing inside a loop (even when only executed conditionally once
every n iterations) is highly likely to cause unwanted performance impacts.
Further, in general use COMMIT
should only be used at the end of a transaction. Code that is not structured to have one transaction
per loop iteration could yield unexpected results if COMMIT
is nonetheless used inside the loop. Code that is structured to have
one transaction per loop iteration should probably be reconsidered.
Note that when dealing with very large data sets, a COMMIT
may be required every n iterations, but the goal should be to avoid
COMMIT
s inside loops.
Noncompliant code example
FOR item IN itemlist
LOOP
-- ...
COMMIT; -- Noncompliant
END LOOP;
Compliant solution
FOR item IN itemlist
LOOP
-- ...
END LOOP;
COMMIT;