I'm reading the book "Oracle Database Transactions and Locking Revealed" - Chapter 4 "Concurrency and Multiversioning". In Oracle we have Restart Update (Oracle will restart the Update statement from scratch). Is there something similar in Postgresql?
Oracle Example:
Tx1: Update table set col1=0 (old value was col1=2);
<no commit>;
Tx2: Update table set col2=... where col1>0;
Tx1: commit;
Tx2: the update is restared by Oracle Database;
Here is a link describing what "restart of an update" means.
This "restarted update" seems to be Oracle's way of dealing with that problem that in
READ COMMITTEDisolation level, the row we want to update could get modified by a concurrent transaction before we get to lock it.PostgreSQL has to deal with the same problem, but it does not solve it by starting the complete
UPDATEstatement from scratch. Instead, it only retrieves the row that has changed again, checks if it still satisfies theWHEREcondition and uses that updated row for further processing.The documentation phrases that as follows:
This technique goes by the internal name of "EvalPlanQual" in PostgreSQL. If you want to know more details, I recommend reading the corresponding section in the executor README.
The Oracle way of doing this seems laborious and expensive (rerun the whole statement), while PostgreSQL is more efficient in re-evaluating only those rows that have changed. On the down side, the PostgreSQL technique can lead to surprising anomalies, as described in this article.