Databases · Middle · Question 21 of 75
How does optimistic locking work?
- 1Updates are queued and applied one at a time
- ✓Correct answer: Rows have a version; an update includes
WHERE version = $read_versionand fails (0 rows) if someone changed it, so the app retries or reports a conflict - 3The database locks rows on read and unlocks them on commit
Explanation
No locks are held while the user thinks, which suits web forms. Under heavy contention many retries happen, and pessimistic locking may be better.