arXiv:2611.02779cs.DBNov 2026

Manuscript Offprint

arXiv:2611.02779

Stop Handcrafting Your Engine! GenDB-V: Towards AI-Generated and Formally Verified Database Systems

Jiale Lao, Immanuel Trummer

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

ABSTRACT

For over 50 years, the database community has developed a wide range of successful engines to answer two fundamental questions: how can database systems run faster, and how can we ensure their correctness? Experience with these engines shows that performance depends on hardware and workloads. As both change over time, we repeatedly redesign and rebuild database systems, a time-consuming and expensive process. Correctness remains another long-standing challenge: recent studies continue to uncover wrong-answer bugs even in mature database engines, despite years of development and testing. To address these, we present GenDB-V, a system that enables AI agents to synthesize database engines specialized to hardware and workloads for performance, and formally verified for correctness. GenDB-V supports specialized implementations of SQL templates and general-purpose engines that accept any query within a supported SQL subset. First, we develop SQLSpec to formalize SQL semantics and deterministically construct fixed, implementation-agnostic synthesis targets for storage preservation and query correctness. Second, we enable joint synthesis of fast code and formal proofs through storage-execution co-optimization, performance-first exploration, and three-layer modular proofs that bridge low-level execution to SQLSpec semantics. Third, we verify the synthesized code and proofs against the fixed synthesis targets in an isolated pipeline, proving SQL correctness and program safety. We evaluate GenDB-V on TPC-H and SEC-EDGAR, a benchmark designed to reduce LLM training-data leakage. For verified template implementations, GenDB-V achieves geometric-mean speedups of 22.0–61.3× over DuckDB and Umbra. For a verified general-purpose engine, GenDB-V also achieves speedups of 1.27–3.4× on TPC-H. GenDB-V also achieves better performance than a testing-based LLM synthesis method, while our audit and tests expose incorrect answers in that method's implementations for 16 of 28 templates. This project is available at https://github.com/GenLang-V/GenDB-V.

1 INTRODUCTION

For more than five decades, the database community has developed successful engines for workloads ranging from short transactions [2, 28] to analytical queries [5, 20, 21], and more [1, 27]. Across these workloads, two fundamental questions have remained central: how can database systems run faster, and how can we ensure their correctness? Despite decades of progress, both remain long-standing challenges that continue to drive database research.

Database performance depends on hardware and workloads, and changes in both have repeatedly led to costly redesigns and

reimplementations. In 2007, H-Store demonstrated the benefits of redesigning transaction processing for main memory, motivating a call for “a complete rewrite” [28]. How often has this call returned? Cloud computing prompted Snowflake to replace fixed-resource assumptions with an elastic warehouse architecture [7]. Embedded analytics motivated DuckDB to bring query processing into the application’s own process [24]. Cheaper, faster SSDs led Umbra to redesign HyPer’s memory-only architecture [21]. More recently, advances in GPU memory and interconnects motivated Sirius, a GPU-native engine that replaces CPU query execution within existing systems [38]. Each new design addresses a new setting, but hardware and workloads continue to evolve, and this never ends.

Ensuring correctness remains difficult: testing continues to expose bugs, while formal verification requires substantial human effort. EET found 35 logic bugs across five database systems, including a PostgreSQL hash-join bug that had survived for 20 years [13]. More recently, SQLancer++ reported 196 bugs across 18 systems, including 140 logic bugs [39]. These findings illustrate why extensive testing cannot establish correctness for every valid input. Formal verification can establish that code satisfies a precise specification for every input covered by the proof. For example, CompCert proves that compilation preserves program behavior [17]. In a compiler-testing study, Csmith reported 79 bugs in GCC and 202 in LLVM, but found no wrong-code bugs in CompCert’s verified passes despite approximately six CPU-years of testing [37]. However, developing such proofs requires substantial effort: verifying seL4’s 8,700-line C kernel required approximately 20 person-years [14].

Recent advances in large language models (LLMs) have enabled agents to optimize software and generate machine-checked proofs [22, 36]. AlphaEvolve [22] improved production code at Google beyond expert-designed implementations, while GSO [11, 25] demonstrates agents’ growing ability to match expert optimizations across real software repositories. Progress in proof generation spans both software and mathematics: VeruSAGE [36] constructs correctness proofs for systems software, AlphaProof [12] produces Lean proofs for Olympiad problems, and Gauss [18] helped formalize the strong prime number theorem in Lean.

Building on these advances, we present GenDB-V to address the performance and correctness challenges of database systems by having AI agents synthesize engines that are specialized to hardware and workloads for performance and formally verified for correctness. Our key insight is to deterministically construct fixed formal synthesis targets, let agents freely explore optimizations and proofs together, and independently verify that their implementations satisfy those targets. The targets define the required behavior without prescribing how it must be implemented. Agents choose storage layouts and execution strategies, then develop intermediate contracts and proofs connecting their code to these targets. An independent verifier checks both that the code satisfies the intermediate contracts and that those contracts establish the fixed requirements.

First, we develop SQLSpec to formalize SQL semantics and deterministically construct fixed, implementation-agnostic synthesis targets for storage preservation and query correctness. To prevent agents from hallucinating or weakening the specification, GenDB-V generates these targets automatically outside the agent's control. SQLSpec defines formal query operators, expressions, predicates, aggregates, and ordering based on PostgreSQL semantics. These definitions account for nulls, duplicate rows, runtime SQL errors, and the multiple valid results permitted by unspecified row order and ordering ties. SQLSpec also provides a verified reference interpreter, which we validate against PostgreSQL and use as the initial baseline for engine synthesis. Using a deterministic SQL-to-SQLSpec translator, GenDB-V constructs fixed synthesis targets that specify only input assumptions and permitted outcomes, leaving storage layouts and execution algorithms open so agents can freely optimize for performance. For storage, the targets require custom storage builders to prove that they preserve all input data without loss. For query execution, the targets require the synthesized code to return a permitted SQLSpec result on every valid database, across all allowed parameter bindings for a SQL template or across all supported queries for a general-purpose engine.

Second, we enable agents to jointly synthesize fast implementations and formal proofs through storage-execution co-optimization, performance-first exploration, and modular verification. GenDB-V lets agents co-design custom storage layouts and execution algorithms together, while also supporting fixed storage when storage changes are disabled. To reason formally about custom storage, the storage builder proves physical layout invariants in a representation predicate that query execution proofs can then use. Because writing formal proofs is expensive in LLM tokens and verifier time, agents first prototype and profile candidate designs in an unverified mode and only develop proofs for the fastest design. Finally, proving low-level execution code directly against recursive SQL semantics in a single step makes the proof too large and complex for agents to develop and for the verifier to check. Agents therefore decompose each proof into three modular layers: storage reader contracts, physical loop invariants, and inductive bridge lemmas that connect physical execution to SQLSpec semantics.

Third, we verify the synthesized code and proofs against the fixed synthesis targets in an isolated pipeline, proving SQL correctness, data preservation, memory and arithmetic safety, race-free parallel execution, and termination. In this pipeline, all specification files and a top-level entry-point function are fixed and read-only outside the agent's control, so agents cannot weaken the synthesis targets. GenDB-V builds this pipeline on Verus [16, 34], which extends a safe subset of Rust with specification and proof annotations. Verus translates the executable Rust code, contracts, loop invariants, and proof lemmas into logical verification conditions, and uses the Z3 SMT solver to check that the code satisfies the agent's intermediate contracts and that those contracts establish the fixed synthesis targets. Once all proofs check, the verified Rust code is compiled into a shared library ready for query execution.

We evaluate GenDB-V on TPC-H at SF100 and SEC-EDGAR at SF3, a benchmark designed to reduce LLM training-data leakage [15]. Experiments cover different parameter bindings and degrees of parallelism. To prevent speedups from stored answers, we require complete, lossless base data and prohibit redundant data copies, materialized joins, stored derived values, precomputed aggregates, and cached query results. Agents may optimize physical storage within a fixed budget. To isolate the benefits of query-code specialization, we also synthesize verified query implementations over fixed plain column arrays, with no storage optimization.

GenDB-V produces verified implementations for all 28 templates and a verified general-purpose engine. Joint storage and query optimization achieves geometric-mean speedups of 22.0–61.3× over DuckDB and Umbra across the two benchmarks. Even over fixed plain arrays, verified query implementations achieve geometric-mean speedups of 1.84–5.49× over DuckDB and Umbra, demonstrating substantial gains from query-code specialization alone. The general engine evolves from a reference interpreter that completes only two TPC-H queries at SF1 within the timeout into an engine that completes the full SF100 workload, achieving total-workload speedups of 1.27–3.4× over DuckDB and Umbra. The engine accepts any well-typed query within SQLSpec's supported fragment over the TPC-H schema. GenDB-V also achieves lower execution times than Bespoke OLAP's testing-based LLM synthesis [35]. Our audit and tests expose incorrect answers on valid inputs in Bespoke OLAP's implementations for 16 of 28 templates, while GenDB-V requires proofs covering every input in the declared domain.

Joint template synthesis costs approximately 2,310acrossbothbenchmarks,andgeneralenginesynthesiscosts2,310 across both benchmarks, and general engine synthesis costs1,229. Compared with the substantial human effort required by prior verification projects, these results demonstrate a promising path toward automating the development of fast, formally verified database systems. Future work should expand SQLSpec's coverage and strengthen confidence in its semantics through community review. Further advances should reduce synthesis cost and enable verification of more language features and larger systems.

The original scientific contributions are the following:

  • SQLSpec and fixed formal synthesis targets. We develop SQLSpec (defining mathematical SQL semantics and a verified reference interpreter) and deterministically construct fixed storage and execution targets for SQL templates and general-purpose query engines outside the agent's control (Section 3).
  • Joint code and proof synthesis with independent verification. We enable agents to synthesize fast, verified implementations through storage-execution co-optimization, performance-first exploration, and three-layer modular proofs, checked by an independent Verus verification pipeline in an isolated environment (Sections 4–5).
  • Experimental evaluation. We evaluate verified template implementations on TPC-H and SEC-EDGAR and a verified general-purpose engine on TPC-H. Template implementations achieve geometric-mean speedups of 22.0–61.3× over DuckDB and Umbra, while the general engine achieves total-workload speedups of 1.27–3.4×. We also analyze synthesis time and monetary cost, code and proof size, the effects of storage optimization, correctness beyond synthesis tests, and case studies (Section 6).

Figure

Figure 1: GenDB-V overview.

References (18)