01 · Context
The question behind the build.
Applications lean on databases they never see inside. Pages, trees, journals and planners decide what a query costs and whether a crash loses data.
Objective
Build a relational engine from the bottom up with nothing but a C99 compiler: storage, transactions, SQL and planning, runnable on Windows, Linux and macOS.
Approach
SQL text passes through a lexer and parser to a virtual machine with a planner and executor. One B+tree implementation backs tables, indexes and the schema catalog, on 4 KiB pages with an LRU cache and a rollback journal.
02 · Architecture
How it fits together.
- 01SQL text
- 02Lexer and parser
- 03Planner and executor
- 04B+ trees on 4 KiB pages
03 · Decisions
The choices that matter.
- 01
One tree, three uses
The same B+tree stores table rows by rowid, index keys in an order-preserving encoding, and the schema catalog itself.
- 02
Durability first
BEGIN, COMMIT and ROLLBACK with a write-ahead rollback journal, fsync on commit and automatic crash recovery when the file is opened.
- 03
A planner that cannot miss rows
Each WHERE clause gets a primary-key seek, an index seek or a full scan. Residual predicates are always re-evaluated, so a chosen path can only narrow the candidates.
The hard part
Every layer constrains the next: the page format shapes the tree, the tree shapes what the planner can seek, and the journal must make all of it recoverable.
04 · Implementation
From idea to working code.
Pythia accepts MySQL and Oracle type spellings, enforces keys and constraints per row, and loads CSV inside a single transaction. It runs as a web console, an interactive terminal or a line-oriented TCP server.
-- Oracle-style DDL
CREATE TABLE emp (
empno NUMBER(5) PRIMARY KEY,
ename VARCHAR2(30) NOT NULL,
salary NUMBER(10,2)
);
-- MySQL-style DDL
CREATE TABLE cust (id BIGINT PRIMARY KEY, name VARCHAR(50));05 · Outcome
The result, and the next question.
An open-source database engine with no dependencies beyond the C standard library. It is the deepest layer in this portfolio: the place where data finally rests.
Summarized from the public README. No performance comparison with other engines is claimed. Read the project documentation (opens in a new tab) ↗