2 Comments

Why do all explanations of OCC use the example of a transaction updating only one row? How would OCC work in the case of a transactional update of, for example, two rows?

Expand full comment

Optimistic Concurrency Control (OCC) often uses a single-row update example for simplicity, as it’s easier to illustrate the basic principles of checking and updating one resource. However, OCC works similarly with multiple rows: each row’s state (e.g., version number or timestamp) is checked individually before performing the update. If two rows are involved in a transaction, OCC will check that neither row has been modified by another transaction since the start of the current transaction. If either row has changed, the transaction will fail, and a retry may be necessary. Otherwise, the transaction can proceed with updating both rows.

Expand full comment