SQL locking and transactions — OSDC notes
Isolation, InnoDB locks, deadlocks, short transactions, ordered updates.
Outline
- Why locks exist — isolation vs throughput
- What your
WHEREreally locks (row/gap) - Isolation levels (
READ COMMITTEDvsREPEATABLE READdefaults) - Deadlock detection and victim selection
- Design: short txns, consistent lock order, idempotent retries
Demo that lands
Two sessions updating rows in opposite order → deadlock. Same work with ordered updates + retries → boredom (the goal).
Invariant: know what you lock, hold it briefly, retry transient failures. See also application error handling.