✏️ Explanatory Question
Level: Advanced — A deep InnoDB internals question that impresses senior interviewers.
MVCC (Multi-Version Concurrency Control) is the technique InnoDB uses to allow readers and writers to work concurrently without blocking each other. Instead of locking rows for reads, InnoDB keeps multiple versions of a row, so each transaction sees a consistent snapshot of the data as of when it started.
DB_TRX_ID (the transaction that last modified it) and DB_ROLL_PTR (a pointer to the previous version).| Read Type | Uses MVCC? | Example |
|---|---|---|
| Consistent (snapshot) read | Yes — reads a version, no locks | Plain SELECT |
| Locking read | No — reads latest, takes locks | SELECT ... FOR UPDATE |
-- Session A (REPEATABLE READ)
START TRANSACTION;
SELECT balance FROM accounts WHERE acc_id = 1; -- sees 1000 (snapshot)
-- Session B (meanwhile)
UPDATE accounts SET balance = 2000 WHERE acc_id = 1;
COMMIT;
-- Session A reads again -> STILL sees 1000, thanks to MVCC snapshot
SELECT balance FROM accounts WHERE acc_id = 1; -- 1000 (consistent read)
-- A locking read bypasses MVCC and sees the latest committed value
SELECT balance FROM accounts WHERE acc_id = 1 FOR UPDATE; -- 2000
COMMIT;