| ISSUE 163/456 · COMPUTER SCIENCE |
~4 MIN |
FOUNDATION / DATA / SNAPSHOTS · READING DATE 2027-03-13 · MARCH 2027 — DATA AND HEAT
How a report reads an earlier row during an edit
START HERE
A report can take several seconds to read records while other people keep editing them. A database is a store of records that programs can search and update. Multiversion concurrency control, or MVCC, is a database method that keeps different record versions so readers can see one coherent earlier condition. A snapshot is the set of changes a particular read is allowed to see, which can exclude edits completed before the report finishes.
|
/ WHY NOW
Without a stable visibility rule, a report could combine a before value from one account with an after value from another. Keeping older row versions allows useful reading without making every editor wait for the report to finish.
|
/ THE IDEA
Imagine two stored balances, A = £60 and B = £40. Another operation transfers £10 from A to B and commits, meaning it finishes successfully and makes its changes eligible to be seen. A snapshot from before that commit sees both older balances; a later snapshot sees both newer balances. The database uses information about which operations were complete or still running when the snapshot was taken. It does not simply choose whichever row version was most recently written when each page happens to arrive. Old versions remain available while relevant readers may still need them.
THE FORMAL IDEA
visible view = changes committed before snapshot + this transaction’s own changes
| A transaction is a group of operations handled as a unit; committed means successfully completed under the database’s rules. This simplified visibility rule describes ordinary table reads, not every special command. | | An isolation mode sets the rules for overlapping transactions. PostgreSQL Read Committed normally takes a fresh snapshot for each statement; Repeatable Read reuses the snapshot taken by its first non-transaction-control statement, not necessarily when the transaction began. |
|
RUN THE TINY EXAMPLE
Change one thing. Predict what happens.
Before transfer: A = 60, B = 40, total = 100. A report takes snapshot S; the transfer then commits A = 50, B = 50. Reading through S still returns 60 and 40, total 100. Change only the snapshot timing to after the commit: the report returns 50 and 50, still total 100.
|
The input change alters which completed world the report sees, not the accounting total. The old view is intentionally consistent rather than a random mixture. A report can therefore be correct for its snapshot while no longer being the newest answer available.
/ SO WHAT?
A long-running reader has a cost: the database may retain older versions longer, delaying cleanup and increasing storage work. That is why a report left open for hours can affect maintenance. Snapshot visibility separates readers from many ordinary row edits; it does not make history free.
ONE CAVEAT |
| MVCC is a mechanism, not a complete isolation guarantee. Different isolation settings use snapshots differently, writers can still block other writers, and schema changes can involve conflicting locks. A stable snapshot also does not automatically prevent every business-rule conflict between concurrent writers. |
KEEP THIS
A snapshot lets a reader see a coherent earlier version while newer edits continue, so always ask when that view was taken.
|
NEXT: Where the rest of an engine’s heat goes
|