4.4.28 · D1Databases

Foundations — MVCC — multi-version concurrency control

2,151 words10 min readBack to topic

This page assumes you know nothing. Before you can read the parent note MVCC — multi-version concurrency control, you must own every word and symbol it throws at you. We build them one at a time, each resting on the one before.


0. What is a "row" and a "transaction"?

The picture below is the whole stage on which MVCC performs: many transactions, one shared table.

Figure — MVCC — multi-version concurrency control

The all-or-nothing promise is one of the ACID Properties (atomicity). MVCC is the mechanism that makes the isolation letter of ACID cheap.


1. txid — the transaction id

We write comparisons like , which reads "is 101 less than 100?" — answer no. Keep that literal reading in mind; every visibility check is just such a question.

Figure — MVCC — multi-version concurrency control
Recall What does

< mean between two txids? "Started earlier." If , transaction began before transaction . ::: The txid counter only increases, so a smaller number is always the older transaction.

(The counter is finite and eventually wraps — see Transaction IDs and Wraparound — but for these foundations, treat it as counting up forever.)


2. "commit" and "abort"


3. xmin and xmax — the birth and death tags

Now we can define the two symbols the parent leans on hardest.

The figure shows a single logical row as a chain of versions, each with its birth and death tags. This chain is the "version chain" the parent note names.

Figure — MVCC — multi-version concurrency control
Recall A version tagged

(xmin=101, xmax=∞) means what? Question ::: Created by transaction 101, and still alive (never replaced), because its death tag is infinity.


4. "version" and "version chain"


5. The snapshot: active set, ,

This is the subtlest symbol group, so we build it slowly.

The figure draws the txid number-line with those boundaries as the walls of your visible world.

Figure — MVCC — multi-version concurrency control
Recall Why is a txid

invisible to a snapshot? Question ::: Because it started after the snapshot was taken — it lives in the transaction's future, which by definition has not happened yet for this reader.


6. Logic symbols: , ,

The visibility rule glues small tests together with logic. Define them once:

Recall Read aloud:

. Question ::: "A is true, AND B is not true." (A holds while B does not.)


7. Isolation, serializability, and locks (the words around MVCC)


Prerequisite map

txid counter

commit or abort status

xmin birth tag

xmax death tag

version

version chain

snapshot xmin xmax active set

AND OR NOT logic

visibility rule

MVCC

isolation and locks

Every box on the left must be solid before the visibility rule on the right makes sense — and that rule is the heart of MVCC.


Equipment checklist

Self-test: cover the right side and answer each.

What does a txid tell you, and what does it not tell you?
It tells start order (smaller = older); it does NOT tell commit/finish order.
What is xmin?
The txid that created this row version — its birth certificate.
What is xmax, and what does mean for it?
The txid that deleted/replaced this version; means still alive, no death yet.
Why does an UPDATE keep the old version instead of overwriting?
So in-flight readers can still read a consistent old value without waiting — the core of MVCC.
Name the three parts of a snapshot.
(oldest running), (next txid = future fence), and the active set (who was mid-flight).
What is precisely?
The next txid to be assigned; anything it is in your future and invisible.
Translate .
A is true AND B is not true.
What is dirty data and why hide it?
A change from an un-committed transaction; it may still abort and vanish, so reading it risks inconsistency.
What does "serializable" mean?
The result equals some strictly one-at-a-time ordering of the transactions.
Which conflict does MVCC still resolve with locks?
Write↔write on the same row.