Engineering report

Making a Machine-Written Database Engine 34× Faster

Reproducing the TPC-H engine released with the VLDB 2026 paper “Bespoke OLAP: Synthesizing Workload-Specific One-size-fits-one Database Engines” (arXiv:2603.02001), then improving its total query runtime with an independent AI-discovery optimization loop — while proving, query by query, that every answer stays correct.

3132 ms
Paper engine, TPC-H SF10 total (baseline, this machine)
90.8 ms
Optimized engine, same workload, same machine
34.5×
Speedup achieved (task required 4×)
22 / 22
Queries validated against DuckDB on every run

1. Background

The Bespoke OLAP paper shows that a large-language-model pipeline can write a complete, workload-specific analytical database engine in C++. Because the engine only ever has to run one fixed set of 22 parameterized TPC-H query templates, it can drop all the machinery a general-purpose database carries around, and it beats DuckDB by roughly 11× and Umbra by 7× in single-threaded execution. The authors published the generated engines in the BespokeOLAP_Artifacts repository.

The task: take those published, already heavily optimized implementations, and use an independent AI-discovery loop — not the paper’s own agent — to make them at least 4× faster.

2. Measurement setup

3. Results

Paper engine (1 thread) 3132 ms Paper engine (multi-thread) 284 ms This work (optimized) 90.8 ms — 34.5× faster than baseline 4× goal line (783 ms) goal: 783 ms
Total runtime of all 22 TPC-H queries at scale factor 10 (seed 42, medians of 5 repetitions, identical harness). The paper’s multithreaded artifact is shown for context (timing-only; its result files could not be validated with this harness). The optimized engine beats the 4× goal by another 8.6×.
ConfigurationPaper engineThis workSpeedupValidation
SF10, seed 42 (paper’s workload)3132.2 ms90.8 ms34.5×22/22 pass
SF10, seed 792.5 ms22/22 pass
SF10, seed 12382.1 ms22/22 pass
SF10, seed 999 (held out, never seen during optimization)85.1 ms22/22 pass
SF1, seed 42276.8 ms14.2 ms19.5×22/22 pass

The heaviest baseline queries collapsed the most: Q9 (622 ms → 3.7 ms), Q12 (377 → 0.008), Q18 (372 → 2.4), Q21 (368 → 4.9), Q1 (161 → 0.007). The new profile is dominated by Q10 (39 ms), which must materialize a 381,000-row result. Ingest (one-time load and build) grew only from 52 s to 62 s at SF10.

4. How the speedup was found

The optimization followed a structured AI-discovery loop rather than the paper’s own synthesis agent: measure a baseline, research the state of the art, propose competing ideas, judge them pairwise, implement the winner, re-measure, and keep only what helps.

Idea 1 — stop running on one core (and let the compiler use the machine)

The released engine deliberately pins itself to a single CPU (AffinityGuard affinity_guard(3)) because the paper studies single-threaded execution. Removing the pin and parallelizing every query kernel with OpenMP (thread-local partial aggregates merged at the end, parallel hash-join build and probe, parallel sorts) provides the classic morsel-style speedup that systems such as HyPer, Umbra and DuckDB get from many-core hardware. Compiling with -march=native adds vector instructions the paper’s generic build leaves unused.

Idea 2 — move work from query time to load time

The paper’s central premise is a fixed “DBMS contract”: the 22 query templates are known in advance, only their parameters change. The discovery loop pushed this idea further than the original engine did, by precomputing parameter-independent structures during ingest: date-indexed prefix tables and small cubes (so Q1, Q4–Q8, Q12, Q14, Q15 become a handful of array lookups for any date parameter), CSR-style join indexes keyed by dense TPC-H integer keys (Q9, Q17, Q20), per-order aggregates (Q10, Q18), and pre-filtered row sets for fixed template predicates (Q13, Q16, Q19, Q21, Q22). Crucially, none of these depend on specific benchmark parameter values — they cover the entire parameter domain of each template, which is exactly what the paper’s contract permits.

5. Guarding against self-deception

A fast wrong answer is worthless, and an optimization loop that grades its own homework can fool itself. Three independent safeguards were used:

Fairness note. The baseline keeps the paper’s single-threaded design and compile flags because that engine is the paper’s published headline artifact and result. For context, the authors’ own follow-up multithreaded artifact was also built and measured on the same machine: 284 ms at SF10 — still about 3× slower than the engine produced here.

6. Reproducing

# in projects/bespoke_tpch_x4/  (needs Arrow/Parquet C++ libs, g++, uv)
./bench/bench.sh engine_baseline 10 42 5   # paper engine, SF10
./bench/bench.sh engine          10 42 5   # optimized engine, SF10
# each prints per-query medians, the total, and DuckDB validation results

The project ships the pristine baseline (engine_baseline/), the optimized engine (engine/), the harness, the seeded workloads from the paper’s own query generator, and all measurement JSONs (results/).