gporca's Rule System: How to Read 119 Rules

The previous post covered gporca’s DP cells. This one covers rules: xforms/ contains 119 files, roughly 44K lines. At first it looks like required reading — it isn’t. Rules are highly homogeneous; understanding three of them teaches you a whole class. 1. There are only three kinds of rules Kind Role Examples Transformation Produce equivalent logical expressions inside the same group Join commutativity, associativity, predicate pushdown Implementation Turn a logical expression into an executable physical operator HashJoin, IndexScan, Sort Enforcer Insert operators to satisfy parent requirements Sort (order), Motion (distribution) Search works like this: transformations grow groups, implementations propose candidates, DP picks the cheapest per group. ...

October 20, 2026 · 3 min · daviszhen

The Optimizer's Cost Model: From Formulas to Calibrated Numbers

The search space decides how many plans you can think of; the rules decide what shapes are reachable; and the cost model decides who wins. Whether an optimizer is usable depends heavily on whether its cost model “makes sense”. This post takes COLUMBIA’s cost model apart, plus the traps we hit when calibrating it on TPC-H. 1. What COLUMBIA’s cost model looks like Minimal: a cost model is a set of constants plus a local-cost formula per physical operator. ...

October 20, 2026 · 3 min · daviszhen

Writing a Query Optimizer: From COLUMBIA to TPC-H

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’t the vocabulary. It’s the way the details constrain each other. 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. ...

October 20, 2026 · 3 min · daviszhen

Reading gporca (Part 1): Only ~11K of Its 400K Lines Are Actually Framework

gporca is Greenplum’s query optimizer: about 401K lines across 935 compilation units. Opening it for the first time is intimidating. But if you slice it by “is this a framework design decision?”, the part that is actually framework is under 10K lines. 1. Four libraries, four roles Many people assume libgpopt is the framework and the other three are “foundational components.” That’s imprecise. They are four different kinds of thing: ...

October 20, 2026 · 4 min · daviszhen

Porting a 1999 Cascades Optimizer to Modern C++: The COLUMBIA Story

If you want to hand-write a query optimizer, the cheapest starting point isn’t inventing one from scratch — it’s understanding a real Cascades implementation first, then getting it to run on your own machine. My sparring partner was COLUMBIA — the master’s thesis implementation by Yongwen Xu at Portland State University (1998–2000, advised by Shapiro and Maier), a textbook-grade Cascades/Volcano optimizer in 19,787 lines across 17 .cpp and 17 .h files. ...

October 20, 2026 · 4 min · daviszhen