Execution Engine
A series in 7 parts

Building a query execution engine

From evaluating one expression against one row to a planner that reads statistics and compiles a query into bytecode you can pause, save, and resume.

A SQL query is a tree. Something has to turn that tree into rows. This series builds that something from scratch, in small steps, in both Go and Clojure. It's at the level of sqlglot's Python SQL engine: small enough to read in an afternoon, real enough that the ideas carry over to SQLite, Postgres, and DuckDB.

Every part has interactive figures. Step through them; they're the point.

    Practice

    Reading about it isn't the same as building it. A few things help it stick:

    The code

    Each part has a standalone lesson in clojure/src/lessonNN and go/lessonNN with a runnable demo; the capstone puts everything together. Or skip the install: the terminal runs the Go programs in your browser, compiled to WebAssembly.

    The capstone is the integrated engine in clojure/src/engine and go/engine: SQL text in, a parser, a planner that reads statistics, and two executors (iterators or bytecode) that must agree.

    cd clojure && clojure -M -m engine.main
    cd go && go run ./cmd/engine