<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>Database on digitalitem: Claude skills library and product lab</title><link>https://digitalitem.online/en/tags/database/</link><description>Recent content in Database on digitalitem: Claude skills library and product lab</description><generator>Hugo</generator><language>en</language><lastBuildDate>Thu, 22 Oct 2026 10:30:00 +0000</lastBuildDate><atom:link href="https://digitalitem.online/en/tags/database/index.xml" rel="self" type="application/rss+xml"/><item><title>Database Kernel (6): WAL, Replay and Checkpoint</title><link>https://digitalitem.online/en/posts/plan-wal-checkpoint/</link><pubDate>Thu, 22 Oct 2026 10:30:00 +0000</pubDate><guid>https://digitalitem.online/en/posts/plan-wal-checkpoint/</guid><description>&lt;p&gt;Transactions make concurrency correct, but machines crash. What recovers the system? An &lt;strong&gt;append-only log&lt;/strong&gt;, plus a marker for where to start replaying.&lt;/p&gt;
&lt;p&gt;The final post in the &lt;a href="https://github.com/daviszhen/plan"&gt;plan&lt;/a&gt; series.&lt;/p&gt;
&lt;h2 id="1-whats-in-the-wal"&gt;1. What&amp;rsquo;s in the WAL&lt;/h2&gt;
&lt;p&gt;&lt;code&gt;walog&lt;/code&gt; is a file storing redo log entries sequentially:&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Type&lt;/th&gt;
&lt;th&gt;Written when&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;insert / delete / update&lt;/td&gt;
&lt;td&gt;a transaction writes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;flush&lt;/td&gt;
&lt;td&gt;a transaction commits&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;checkpoint&lt;/td&gt;
&lt;td&gt;everything before it is already applied to tables&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;create table / schema / use table&lt;/td&gt;
&lt;td&gt;DDL and table switching&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;Key convention: &lt;strong&gt;entries between two flushes belong to one transaction&lt;/strong&gt;, so replay needs no extra transaction-boundary metadata.&lt;/p&gt;</description></item><item><title>Database Kernel (5): Transactions, Timestamps and GC</title><link>https://digitalitem.online/en/posts/plan-transactions-mvcc/</link><pubDate>Thu, 22 Oct 2026 10:25:00 +0000</pubDate><guid>https://digitalitem.online/en/posts/plan-transactions-mvcc/</guid><description>&lt;p&gt;Multiple versions make concurrent reads and writes possible, but versions aren&amp;rsquo;t free: &lt;strong&gt;who creates them, who can see them, and when they can be dropped&lt;/strong&gt; all need explicit answers.&lt;/p&gt;
&lt;p&gt;Part five of the &lt;a href="https://github.com/daviszhen/plan"&gt;plan&lt;/a&gt; series.&lt;/p&gt;
&lt;h2 id="1-txnmgr-holds-very-little"&gt;1. TxnMgr holds very little&lt;/h2&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-go" data-lang="go"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#a6e22e"&gt;TxnMgr&lt;/span&gt;{
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#a6e22e"&gt;currentStartTs&lt;/span&gt; &lt;span style="color:#66d9ef"&gt;uint64&lt;/span&gt; &lt;span style="color:#75715e"&gt;// starts at 2, +1 per txn, &amp;lt; 2^62&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#a6e22e"&gt;currentTxnId&lt;/span&gt; &lt;span style="color:#66d9ef"&gt;uint64&lt;/span&gt; &lt;span style="color:#75715e"&gt;// starts at 2^62, +1 per txn&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#a6e22e"&gt;lowestActiveId&lt;/span&gt; &lt;span style="color:#66d9ef"&gt;uint64&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#a6e22e"&gt;lowestActiveStart&lt;/span&gt; &lt;span style="color:#66d9ef"&gt;uint64&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#a6e22e"&gt;activeTxns&lt;/span&gt; []&lt;span style="color:#a6e22e"&gt;Txn&lt;/span&gt; &lt;span style="color:#75715e"&gt;// created, not committed/rolled back&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#a6e22e"&gt;committedTxns&lt;/span&gt; []&lt;span style="color:#a6e22e"&gt;Txn&lt;/span&gt; &lt;span style="color:#75715e"&gt;// committed, not GC&amp;#39;d&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#a6e22e"&gt;oldTxns&lt;/span&gt; []&lt;span style="color:#a6e22e"&gt;Txn&lt;/span&gt; &lt;span style="color:#75715e"&gt;// GC-able, not GC&amp;#39;d&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The two counters start in different ranges so &lt;strong&gt;timestamps and transaction ids never collide&lt;/strong&gt;:&lt;/p&gt;</description></item><item><title>Database Kernel (4): Storage — Row Groups, Column Segments and Four Layers</title><link>https://digitalitem.online/en/posts/plan-storage-layout/</link><pubDate>Thu, 22 Oct 2026 10:20:00 +0000</pubDate><guid>https://digitalitem.online/en/posts/plan-storage-layout/</guid><description>&lt;p&gt;Execution deals in chunks; storage answers a different question: &lt;strong&gt;where those chunks live, at what granularity, and how updates and versions fit in&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;Part four of the &lt;a href="https://github.com/daviszhen/plan"&gt;plan&lt;/a&gt; series: the four-layer in-memory layout.&lt;/p&gt;
&lt;h2 id="1-four-layers"&gt;1. Four layers&lt;/h2&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;table
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;└── row group (122,880 rows)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; └── column data (one column)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; └── column segment (256 KB block, up to 60 vectors)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; └── vector (2,048 rows)
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The numbers are aligned on purpose:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;60 × 2,048 = 122,880&lt;/code&gt; — one row group is exactly 60 full vectors;&lt;/li&gt;
&lt;li&gt;a segment holds up to 60 vectors, about 256 KB;&lt;/li&gt;
&lt;li&gt;a vector is the smallest read/write unit and the executor&amp;rsquo;s batch size.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Alignment pays off&lt;/strong&gt;: scans skip whole segments and read whole vectors, with no cross-block stitching.&lt;/p&gt;</description></item><item><title>Database Kernel (3): Execution — Vectors, Chunks and the Vectorized Volcano Model</title><link>https://digitalitem.online/en/posts/plan-vector-execution/</link><pubDate>Thu, 22 Oct 2026 10:15:00 +0000</pubDate><guid>https://digitalitem.online/en/posts/plan-vector-execution/</guid><description>&lt;p&gt;The plan tree settles &lt;em&gt;what&lt;/em&gt; to do; execution settles &lt;em&gt;how to do it batch by batch&lt;/em&gt;. The key here isn&amp;rsquo;t the algorithm — it&amp;rsquo;s &lt;strong&gt;memory layout&lt;/strong&gt;: the same data arranged differently can be an order of magnitude faster.&lt;/p&gt;
&lt;p&gt;Part three of the &lt;a href="https://github.com/daviszhen/plan"&gt;plan&lt;/a&gt; series.&lt;/p&gt;
&lt;h2 id="1-vector-logically-an-array-physically-maybe-not"&gt;1. vector: logically an array, physically maybe not&lt;/h2&gt;
&lt;p&gt;A &lt;code&gt;vector&lt;/code&gt; is logically a fixed-size array, but it has several physical representations:&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Representation&lt;/th&gt;
&lt;th&gt;Use case&lt;/th&gt;
&lt;th&gt;Stores&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;FLAT&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;default&lt;/td&gt;
&lt;td&gt;contiguous array, same as logical&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;CONSTANT&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;whole column identical&lt;/td&gt;
&lt;td&gt;one value&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;DICTIONARY&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;low-cardinality strings&lt;/td&gt;
&lt;td&gt;indices + dictionary&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;SEQUENCE&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;increasing sequence&lt;/td&gt;
&lt;td&gt;base + increment&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;UNIFIED&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;generic algorithms&lt;/td&gt;
&lt;td&gt;contiguous data + selection&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;Why so many? Because many columns during execution are constant or repetitive:&lt;/p&gt;</description></item><item><title>Database Kernel (2): From Syntax Tree to Plan Tree — Filter Pushdown and Join Ordering</title><link>https://digitalitem.online/en/posts/plan-query-planning/</link><pubDate>Thu, 22 Oct 2026 10:10:00 +0000</pubDate><guid>https://digitalitem.online/en/posts/plan-query-planning/</guid><description>&lt;p&gt;Bind produces scopes and expressions; execution needs a &lt;strong&gt;plan tree&lt;/strong&gt;. The conversion in between decides whether a query merely runs or runs fast.&lt;/p&gt;
&lt;p&gt;This is part two of the &lt;a href="https://github.com/daviszhen/plan"&gt;plan&lt;/a&gt; series: how the plan tree is built, and the two optimizations that matter most.&lt;/p&gt;
&lt;h2 id="1-the-minimal-plan-node"&gt;1. The minimal plan node&lt;/h2&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-go" data-lang="go"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;type&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;LogicalOperator&lt;/span&gt; &lt;span style="color:#66d9ef"&gt;struct&lt;/span&gt; {
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#a6e22e"&gt;Typ&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;LOT&lt;/span&gt; &lt;span style="color:#75715e"&gt;// scan / filter / project / join / agg / order / limit&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#a6e22e"&gt;Children&lt;/span&gt; []&lt;span style="color:#f92672"&gt;*&lt;/span&gt;&lt;span style="color:#a6e22e"&gt;LogicalOperator&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#75715e"&gt;// node-specific extra fields&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Generation follows the bind order:&lt;/p&gt;</description></item><item><title>Database Kernel (1): Bind Is Semantic Analysis, Not Syntax Checking</title><link>https://digitalitem.online/en/posts/plan-bind-and-cte/</link><pubDate>Thu, 22 Oct 2026 10:05:00 +0000</pubDate><guid>https://digitalitem.online/en/posts/plan-bind-and-cte/</guid><description>&lt;p&gt;People often assume SQL parsing means &amp;ldquo;turn the string into a tree&amp;rdquo; and then execution can start. The step in between — &lt;strong&gt;bind&lt;/strong&gt; — is the most underrated: it decides which table and column every name refers to, in which scope.&lt;/p&gt;
&lt;p&gt;This is the first post in the &lt;a href="https://github.com/daviszhen/plan"&gt;plan&lt;/a&gt; implementation series: what bind does, and why the order matters.&lt;/p&gt;
&lt;h2 id="1-four-components"&gt;1. Four components&lt;/h2&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Component&lt;/th&gt;
&lt;th&gt;Role&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;Builder&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;The driver for semantic analysis, one per select; also holds partial results&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;BindContext&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;A scope: which relations are visible here; scopes nest&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;Binding&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;The definition of a relation (table or subquery) and its columns&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;Expr&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Everything except relations becomes an expression&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;The key design is &lt;strong&gt;nested BindContexts&lt;/strong&gt;: a subquery isn&amp;rsquo;t &amp;ldquo;a new parser&amp;rdquo;, it&amp;rsquo;s a new scope on top of the parent. Name lookup walks up until it finds something or errors.&lt;/p&gt;</description></item><item><title>The Optimizer's Cost Model: From Formulas to Calibrated Numbers</title><link>https://digitalitem.online/en/posts/optimizer-cost-model/</link><pubDate>Tue, 20 Oct 2026 13:05:00 +0000</pubDate><guid>https://digitalitem.online/en/posts/optimizer-cost-model/</guid><description>&lt;p&gt;The search space decides how many plans you can think of; the rules decide what shapes are reachable; and &lt;strong&gt;the cost model decides who wins&lt;/strong&gt;. Whether an optimizer is usable depends heavily on whether its cost model &amp;ldquo;makes sense&amp;rdquo;.&lt;/p&gt;
&lt;p&gt;This post takes COLUMBIA&amp;rsquo;s cost model apart, plus the traps we hit when calibrating it on TPC-H.&lt;/p&gt;
&lt;h2 id="1-what-columbias-cost-model-looks-like"&gt;1. What COLUMBIA&amp;rsquo;s cost model looks like&lt;/h2&gt;
&lt;p&gt;Minimal: a cost model is &lt;strong&gt;a set of constants plus a local-cost formula per physical operator&lt;/strong&gt;.&lt;/p&gt;</description></item><item><title>Data Version Control: Why a Database Needs Git</title><link>https://digitalitem.online/en/posts/data-versioning-why/</link><pubDate>Tue, 20 Oct 2026 12:58:00 +0000</pubDate><guid>https://digitalitem.online/en/posts/data-versioning-why/</guid><description>&lt;p&gt;Git gave code cheap branching, rollback and merge. Data never got the same deal — because data is huge; one copy is a terabyte.&lt;/p&gt;
&lt;p&gt;But a trend is changing that: &lt;strong&gt;the people editing data are turning into AI clusters.&lt;/strong&gt; When the scale and frequency of writes go up an order of magnitude, branch / merge / rollback move from &amp;ldquo;nice feature&amp;rdquo; to &amp;ldquo;the only way this can be safe&amp;rdquo;.&lt;/p&gt;
&lt;h2 id="1-what-data-versioning-needs"&gt;1. What data versioning needs&lt;/h2&gt;
&lt;p&gt;Strip the product narrative and a data version system needs at least three things:&lt;/p&gt;</description></item><item><title>Writing a Query Optimizer: From COLUMBIA to TPC-H</title><link>https://digitalitem.online/en/posts/writing-a-query-optimizer/</link><pubDate>Tue, 20 Oct 2026 12:50:00 +0000</pubDate><guid>https://digitalitem.online/en/posts/writing-a-query-optimizer/</guid><description>&lt;p&gt;Query optimizers are the component everyone uses and few people write. You can recite Join Order, subquery unnesting and cost models in an interview — but actually writing an optimizer that survives all 22 TPC-H queries teaches you that the hard part isn&amp;rsquo;t the vocabulary. It&amp;rsquo;s the way the details constrain each other.&lt;/p&gt;
&lt;p&gt;This series is a record of one such attempt: from porting a textbook Cascades implementation, to making it digest TPC-H, to admitting the traps it fell into.&lt;/p&gt;</description></item><item><title>Implementing Git for Data on DuckDB (Part 1): Feasibility — Why an Analytical Database Can Grow Version Control</title><link>https://digitalitem.online/en/posts/duckdb-git4data-why/</link><pubDate>Tue, 20 Oct 2026 08:00:00 +0000</pubDate><guid>https://digitalitem.online/en/posts/duckdb-git4data-why/</guid><description>Git4Data wants branches, rollbacks and merges for data. First question: how far is DuckDB&amp;#39;s existing MVCC and row-group versioning from a &amp;#39;data time machine&amp;#39;?</description></item><item><title>Rewriting Lucene in C++ (Part 1): Byte-Level Compatibility — When Java Reads a C++-Written Index</title><link>https://digitalitem.online/en/posts/lucene-cpp-format/</link><pubDate>Tue, 20 Oct 2026 07:00:00 +0000</pubDate><guid>https://digitalitem.online/en/posts/lucene-cpp-format/</guid><description>Not inventing a format, but cloning Lucene 10.4&amp;#39;s on-disk format: so Java CheckIndex accepts a C++-written index and C++ reads a Java-written one byte-for-byte identically.</description></item><item><title>Reading gporca (Part 3): The Key of a DP Cell — (Group, Required Properties, Stage)</title><link>https://digitalitem.online/en/posts/gporca-dp-context/</link><pubDate>Tue, 20 Oct 2026 06:50:00 +0000</pubDate><guid>https://digitalitem.online/en/posts/gporca-dp-context/</guid><description>The optimization problem isn&amp;#39;t &amp;#39;find one optimal plan per group&amp;#39; — it&amp;#39;s &amp;#39;per (group, required properties, stage)&amp;#39;. COptimizationContext is the coordinate of that cell.</description></item><item><title>Reading gporca (Part 2): The Reference-Count Gate That Turns Recursive Search into a Pausable Task Network</title><link>https://digitalitem.online/en/posts/gporca-scheduler-refcount/</link><pubDate>Tue, 20 Oct 2026 06:40:00 +0000</pubDate><guid>https://digitalitem.online/en/posts/gporca-scheduler-refcount/</guid><description>gporca&amp;#39;s scheduler uses one counter and a set of state machines to flatten the entire recursive search into suspendable, resumable, deduplicated tasks.</description></item><item><title>Reading gporca (Part 1): Only ~11K of Its 400K Lines Are Actually Framework</title><link>https://digitalitem.online/en/posts/gporca-framework/</link><pubDate>Tue, 20 Oct 2026 06:30:00 +0000</pubDate><guid>https://digitalitem.online/en/posts/gporca-framework/</guid><description>Slicing gporca by &amp;#39;is this a framework design decision&amp;#39;: what each of its four libraries really is, the six mechanisms worth reading, and a practical reading order.</description></item><item><title>Making an Optimizer Run TPC-H: Lossless Conversion and Execution Reconciliation for 22 Queries</title><link>https://digitalitem.online/en/posts/tpch-lossless-and-execution/</link><pubDate>Tue, 20 Oct 2026 06:10:00 +0000</pubDate><guid>https://digitalitem.online/en/posts/tpch-lossless-and-execution/</guid><description>From 13/22 to 22/22: converting every TPC-H query as-is into the optimizer, checking lossless equivalence with DuckDB&amp;#39;s AST, and executing the resulting plans against the original queries.</description></item><item><title>Porting a 1999 Cascades Optimizer to Modern C++: The COLUMBIA Story</title><link>https://digitalitem.online/en/posts/columbia-port/</link><pubDate>Tue, 20 Oct 2026 06:00:00 +0000</pubDate><guid>https://digitalitem.online/en/posts/columbia-port/</guid><description>How a 19,787-line MFC optimizer from 1999 got rebuilt, debugged, and made to run its own test corpus — without MFC and without Windows.</description></item></channel></rss>