Database Kernel (6): WAL, Replay and Checkpoint

Transactions make concurrency correct, but machines crash. What recovers the system? An append-only log, plus a marker for where to start replaying. The final post in the plan series. 1. What’s in the WAL walog is a file storing redo log entries sequentially: Type Written when insert / delete / update a transaction writes flush a transaction commits checkpoint everything before it is already applied to tables create table / schema / use table DDL and table switching Key convention: entries between two flushes belong to one transaction, so replay needs no extra transaction-boundary metadata. ...

October 22, 2026 · 2 min · daviszhen

Database Kernel (5): Transactions, Timestamps and GC

Multiple versions make concurrent reads and writes possible, but versions aren’t free: who creates them, who can see them, and when they can be dropped all need explicit answers. Part five of the plan series. 1. TxnMgr holds very little TxnMgr{ currentStartTs uint64 // starts at 2, +1 per txn, < 2^62 currentTxnId uint64 // starts at 2^62, +1 per txn lowestActiveId uint64 lowestActiveStart uint64 activeTxns []Txn // created, not committed/rolled back committedTxns []Txn // committed, not GC'd oldTxns []Txn // GC-able, not GC'd } The two counters start in different ranges so timestamps and transaction ids never collide: ...

October 22, 2026 · 2 min · daviszhen

Database Kernel (4): Storage — Row Groups, Column Segments and Four Layers

Execution deals in chunks; storage answers a different question: where those chunks live, at what granularity, and how updates and versions fit in. Part four of the plan series: the four-layer in-memory layout. 1. Four layers table └── row group (122,880 rows) └── column data (one column) └── column segment (256 KB block, up to 60 vectors) └── vector (2,048 rows) The numbers are aligned on purpose: 60 × 2,048 = 122,880 — one row group is exactly 60 full vectors; a segment holds up to 60 vectors, about 256 KB; a vector is the smallest read/write unit and the executor’s batch size. Alignment pays off: scans skip whole segments and read whole vectors, with no cross-block stitching. ...

October 22, 2026 · 2 min · daviszhen

Database Kernel (3): Execution — Vectors, Chunks and the Vectorized Volcano Model

The plan tree settles what to do; execution settles how to do it batch by batch. The key here isn’t the algorithm — it’s memory layout: the same data arranged differently can be an order of magnitude faster. Part three of the plan series. 1. vector: logically an array, physically maybe not A vector is logically a fixed-size array, but it has several physical representations: Representation Use case Stores FLAT default contiguous array, same as logical CONSTANT whole column identical one value DICTIONARY low-cardinality strings indices + dictionary SEQUENCE increasing sequence base + increment UNIFIED generic algorithms contiguous data + selection Why so many? Because many columns during execution are constant or repetitive: ...

October 22, 2026 · 3 min · daviszhen

Database Kernel (2): From Syntax Tree to Plan Tree — Filter Pushdown and Join Ordering

Bind produces scopes and expressions; execution needs a plan tree. The conversion in between decides whether a query merely runs or runs fast. This is part two of the plan series: how the plan tree is built, and the two optimizations that matter most. 1. The minimal plan node type LogicalOperator struct { Typ LOT // scan / filter / project / join / agg / order / limit Children []*LogicalOperator // node-specific extra fields } Generation follows the bind order: ...

October 22, 2026 · 3 min · daviszhen

Database Kernel (1): Bind Is Semantic Analysis, Not Syntax Checking

People often assume SQL parsing means “turn the string into a tree” and then execution can start. The step in between — bind — is the most underrated: it decides which table and column every name refers to, in which scope. This is the first post in the plan implementation series: what bind does, and why the order matters. 1. Four components Component Role Builder The driver for semantic analysis, one per select; also holds partial results BindContext A scope: which relations are visible here; scopes nest Binding The definition of a relation (table or subquery) and its columns Expr Everything except relations becomes an expression The key design is nested BindContexts: a subquery isn’t “a new parser”, it’s a new scope on top of the parent. Name lookup walks up until it finds something or errors. ...

October 22, 2026 · 3 min · daviszhen