mskql

An in-memory SQL engine written in C—faster than PostgreSQL, built entirely by AI

Martin S. Kristiansen  ·  github.com/martinsk/mskql  ·  Tutorials


mskql distills the core ideas of a database engine—wire protocol, parser, query executor, storage—into ~24,000 lines of C with zero external dependencies. One .c file per subsystem. Three AI agents built it in iterative rounds: no human wrote any C code or SQL test. 960+ test cases, every one memory-checked. Connect with psql on port 5433 or try it in the browser via WebAssembly.

PostgreSQL wire-protocol compatible

mskql implements PostgreSQL wire protocol v3: Simple Query, Extended Query (prepared statements, $1/$2 parameters), and COPY. Connect with psql, pgAdmin, DBeaver, or any language driver. Default port 5433.

make && ./build/mskql                         # build & start
psql -h 127.0.0.1 -p 5433 -U test -d mskql   # connect

Performance vs PostgreSQL

Batch latency (single client) and concurrent throughput (4 threads, 5s).

mskql PostgreSQL
WorkloadTypeRatio
aggregatebatch0.12×mskql 8× faster
distinctbatch0.15×mskql 7× faster
insert_bulkbatch0.33×mskql 3× faster
order_bybatch0.49×mskql 2× faster
aggregatethroughput9.21× QPS52,670 vs 5,720 QPS
insertthroughput2.06× QPS56,658 vs 27,520 QPS
full_scanthroughput0.91× QPSnetwork-bound

→ Full benchmark comparison  ·  Historical charts

Built entirely by AI agents

Three agents in iterative rounds. Challenger writes adversarial SQL tests. Reviewer flags code-quality issues. Writer fixes until all 960+ tests pass. No human wrote any C code or SQL test cases.

→ Read more about the process

Challenger adversarial tests Writer writes & fixes Reviewer code review iterate until all 960+ tests pass

Try it — right here

A fully functional mskql database running entirely in your browser via WebAssembly—no server, no network requests. Choose an example or write your own SQL.

Loading WebAssembly…
Run a query to see results here.

→ Open full playground  (more space, more examples)

Build & connect

Ten queries from CREATE TABLE to recursive CTEs, all through psql.

Getting started →

Read the source

~24,000 lines of C11. Every subsystem in a single file.

GitHub →

Reference

Architecture — wire protocol, parser, vectorized executor, storage. One .c file per subsystem.
SQL reference — DDL, DML, joins, aggregation, window functions, CTEs, subqueries, 30+ built-in functions.  Grammar
Testing — 960+ test cases, every one under a memory-safety checker. Parallel execution across all cores.
Benchmarks — mskql vs PostgreSQL on 19 batch workloads and 7 throughput workloads.  Historical charts