A small relational database engine written from scratch in C++17. It parses a focused subset of SQL, stores each table in checksummed 4 KB pages, keeps a B+ tree index for every field, and recovers each statement atomically after a crash through a write-ahead log.
I wrote the first version in 2023 while learning C++ and rebuilt the storage engine in 2026.
The original-2023 tag keeps the first version.
A session in the CLI from a local Release build, November 13, 2026.
You need a C++17 compiler and CMake 3.20 or newer; the build has no third-party dependency and downloads nothing.
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release
cmake --build build --parallel
ctest --test-dir build --output-on-failure
./build/run_sqlType end to exit and cls to clear the screen.
SQL>> create table student fields first, last, major, age
SQL>> insert into student values Grace, Hopper, CS, 30
SQL>> select first, major from student where major = CS
The table answers a WHERE filter from the per-field B+ tree indexes after the shunting-yard step turns the filter into postfix form.
Each statement that changes a table first writes its complete after-image to <table>.sql2-wal and syncs it, and only then writes the changed pages to <table>.sql2.
A crash before the WAL write leaves the old table, a crash after the WAL is synced recovers the new table on open, and a torn WAL record makes the open fail with a corruption error instead of guessing.
CREATE TABLE,INSERT INTO, andSELECTwith*or a field list.WHEREwith=,!=,<,<=,>,>=, andANDandORwith parentheses.- Tables that persist across CLI sessions, with page, index, and WAL corruption rejected on open.
- Batch runs from the sample command files in
batch/. - Copy-first migration from the 2023 fixed-width format.
It has no joins, multi-statement transactions, schemas, query planning, updates, or deletes, and it has no locking, so run only one writer at a time.
Values are stored and compared as strings, so 9 sorts after 10.
The CTest suite covers SQL behavior, parser safety, B+ tree splits, stable untouched pages, WAL ordering, a crash at every traced write and fsync, corruption rejection, recovery that can run twice, v1 migration, maximum-width rows, the CLI, and both batch fixtures. Tests run in the build directory and leave no database files in the source tree. CI runs a Release build and the suite on Linux.
- Usage: the full grammar, the CLI's files and errors, storage inspection, v1 migration, limits, and the sanitizer build.
- Design and invariants: the command path, source layout, and storage and query rules.
- Storage format v2: the byte layout, checksums, and recovery order.
