The first two posts made history readable. This one covers what makes a data version system actually useful: branches and changes.
1. The branch model
A branch isn’t “a copy of the data”; it’s a combination of three things:
branch = pin (which commit) + name + lineage (parent / base_line)
+ optional storage (materialized copy) or delta (changes relative to a base)
- materialize: really copy the table; reads go straight to the copy;
- delta: store only “which keys were removed from the base, which rows were added”; reads compose;
- update in a delta is a removal plus an addition of the same key (replacement pairing).
This design brings the cost of “create a branch” from “copy a table” down to “register one metadata row.”
2. diff: two paths, one goal
diff finds the difference between two references. We ended up with two paths:
| Path | Trigger | Approach |
|---|---|---|
| row-id path | Same table, neither side has a delta | Compare row ids and visibility directly, O(rows) |
| key path | Different tables, or either side has a delta | Align on the primary key (integer keys use a bit-pattern fast path) |
Memory is a measured ceiling:
| Scenario | Peak RSS | Time |
|---|---|---|
| 1M rows, cross-table key path | 344 MB | 6.2 s |
| 1M rows, same-table row-id path | 248 MB | — |
| 400K-row delta self-diff | 151 MB | — |
Broken down, the key path’s own structures are about 133 B/row (arena ~50, hash table ~40, columns ~10). This isn’t “maybe squeeze a bit more” — at 10M rows it’s gigabytes, so the conclusion is: write the diff’s scale limit into the docs instead of pretending it’s unbounded.
3. pick, merge, clone, PITR
- pick: apply a reference’s changes onto the current branch, with conflict policies (FAIL / SKIP / ACCEPT);
- merge: three-way merge (base, left, right), policies configurable;
- clone: file-level zero-copy via
clonefile/FICLONE, measured as essentially free; - PITR: point-in-time recovery by choosing the newest reference at or before T;
- quotas: limit the number of snapshots/branches.
One interesting measured comparison (1M rows):
| Operation | Time | Memory |
|---|---|---|
| Materialize a full copy | 0.16 s | 45 MB |
| Write a 50% delta | 2.22 s | 114 MB |
| Read the copy | 0.02 s | 26 MB |
| Read the delta | 1.90 s | 58 MB |
Conclusion: sparse changes favor delta; dense changes favor a copy. This replaced our initial — wrong — intuition that “delta is always cheaper,” and went into the design note.
4. Verification discipline: the revert check
The hardest part of this feature isn’t writing code — it’s proving it isn’t wrong. We established a discipline whose most important rule is the revert check:
Every fix must make a named test line fail when the fix is removed.
Examples:
- Remove the “pin blocks appends” fix → a retention test reads 610K rows instead of 600K;
- Remove the “key-path diff” → merge silently loses a change;
- Remove the “merge ancestor guard” → merge silently succeeds and reverts the ancestor.
Without this rule you can’t tell “fixed” from “not covered by a test yet.”
5. Test scale
Final feature test set:
| Suite | Scale |
|---|---|
| git4data feature tests | 85 files / 4,592 assertions |
| Storage suite | 655 cases / 102,325 assertions |
| Index suite | 151 cases / 85,991 assertions |
| Full regression | 7,341 cases (0 feature-related failures) |
Plus four build axes (Release / FORCE_ASSERT / ALTERNATIVE_VERIFY / config sweep) and a set of scripts (74 retention checks, 47 crash-consistency checks, 34 MatrixOne parity checks…).
6. Summary
- A branch is “reference + lineage,” not “copy of data”;
- diff has two paths; its scale limit must be measured and written down;
- delta vs copy depends on change density — measure, don’t assume;
- the revert check is a version control system’s own unit test.
Next: moving the registry out of the checkpoint metadata block into ordinary tables — transactions, crash consistency, and “hidden but readable.”
Related
- Implementing Git for Data on DuckDB (Part 4): Moving Metadata into Tables — Transactions, Crash Consistency and ‘Hidden but Readable’
- Implementing Git for Data on DuckDB (Part 2): Pinning History — Snapshots, Retention Watermarks and AT SNAPSHOT
- Rewriting Lucene in C++ (Part 1): Byte-Level Compatibility — When Java Reads a C++-Written Index
Get the next essay
New essays on products, business and tech — plus what the experiment's numbers actually say.