Lesson 0009 · Interleaved review
Eight lessons, mixed on purpose — the difficulty of jumping between pillars is what turns fluency into durable, transferable mastery.
This lesson teaches nothing new. It interleaves — the retrieval questions hop between indexing, concurrency, and durability from one item to the next. That hopping is harder than a themed quiz, and the extra effort is the point: it trains you to first recognize which concept applies, the skill a real slow query or incident actually demands. Answer everything from memory; if one stings, follow its link and re-read.
A lookup by primary key returns the full row in:
Under REPEATABLE READ, the read snapshot is fixed at:
On the type ladder, the rung between ref and index is:
An UPDATE on an unindexed column tends to lock:
At COMMIT (default settings), what must be durable on disk?
Index (a, b) cannot perform a seek for a filter on:
(a) and (a,b) work; b alone skips the leading column.With async replication, a source failover can lose:
Which predicate lets an index on the column seek?
A plain SELECT meeting a concurrent UPDATE of the same row will:
Besides ROLLBACK, the undo log also powers:
Extra: Using index in EXPLAIN means the query was:
In REPEATABLE READ, next-key locks exist to stop:
Higher-order transfer: read each scenario, commit to an answer out loud, then expand to check. These are the shapes real problems arrive in.
created_at exists, but EXPLAIN shows key: NULL, type: ALL for WHERE YEAR(created_at) = 2026. Why, and what's the fix?created_at, not YEAR(...) of it (0004). Fix: rewrite as a
bare-column range: created_at >= '2026-01-01' AND created_at < '2027-01-01' → now
type: range (0003). Or add a functional index on (YEAR(created_at)).WHERE tenant_id = ? AND status = ? and sorts ORDER BY created_at. Design one index that serves the filter and kills the filesort.INDEX (tenant_id, status, created_at). The two equality columns form the leftmost prefix
for the seek (0002); because created_at follows them in the index, the rows already
arrive in created_at order, so no Using filesort (0003). Equality columns
first, the ORDER BY column last.SELECT there might block our writes on the source." True?SELECT is a lock-free MVCC snapshot read (0005) served from undo (0007) —
it takes no locks even locally, and a replica is a separate server anyway. Reads never block writers.
(What a replica can show is slightly stale data due to replication lag — a different issue,
from 0008.)UPDATE jobs SET state='done' WHERE state='running' and you're getting frequent deadlocks. state has no index. What's the connection, and one fix?state, each UPDATE scans and locks every row it
examines (0006 keystone: locks sit on the index records walked; no index → scans the
clustered index). Wide, overlapping lock footprints across two workers → deadlock cycles.
Fix: index state so each statement locks only matching rows; also keep
transactions short and process in a consistent order (0006).innodb_flush_log_at_trx_commit = 1 — full local durability: the
redo is fsync'd at every commit, so a single-server crash loses nothing (0007). (b)
Semisynchronous replication — the commit waits until ≥1 replica has received
the binlog events, so if the whole source machine dies, the committed order still exists on a replica
to fail over to (0008). Local durability + a guaranteed remote copy.That's the signal telling you where to spend a re-read — not a failure. Open the linked lesson, skim its one keystone callout, and re-attempt the scenario tomorrow. Spacing + a second attempt is worth more than re-reading now.
The course map puts all eight keystones and a spaced-review schedule on one printable page. Revisit it, not the lessons, for maintenance.