NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Parser Knows Best: Testing DBMS with Coverage-Guided Grammar-Rule Traversal

Yu Liang, Hong HuarXiv 2025 · DOI

Introduction

Database Management Systems (DBMSs), such as MySQL and SQLite, serve as the foundational infrastructure for modern software applications. Ensuring their reliability is paramount; however, testing these systems is notoriously difficult due to the complexity and variability of SQL dialects. Each DBMS often implements a unique, evolving "flavor" of SQL, making it hard for generic testing tools to achieve deep code coverage.

Existing DBMS testing methodologies generally fall into two categories: generation-based and mutation-based. Generation-based tools rely on manually written templates to create queries, which are high-quality but struggle to keep pace with new features and often miss "corner case" syntax. Mutation-based tools utilize a seed corpus of existing valid queries and apply modifications. However, these are limited by the quality of the initial seeds; if a specific feature (e.g., a rare index type) is absent from the corpus, the fuzzer will never explore it. To bridge this gap, we present ParserFuzz, a framework that leverages the database's own parser definitions to achieve comprehensive, automated testing.

Methodology: The ParserFuzz Framework

The core innovation of ParserFuzz is the realization that the "ground truth" of a database's supported syntax resides within its source code—specifically in parser definition files (e.g., Bison, Yacc, or Lemon). By extracting grammar directly from these files, ParserFuzz eliminates the need for manual templates or human-curated seed corpora.

Overview of the ParserFuzz architecture, illustrating the flow from SQL syntax definitions to bug discovery.

System Architecture

As shown in the figure above, ParserFuzz operates through a multi-stage pipeline:

  1. Grammar Extraction: The system automatically parses the DBMS's syntax definition files to build a complete map of every supported SQL command and structure.
  2. Rule-based Generation: Starting from a blank slate, the tool traverses these grammar rules to generate diverse, syntactically correct queries. To manage the "path explosion" caused by recursive SQL grammar (e.g., nested expressions), ParserFuzz categorizes rules as simple, normal, or complex. It employs a Multi-Armed Bandit (MAB) algorithm—specifically an $\epsilon$-Greedy approach—to prioritize rules that lead to successful and interesting query completions.
  3. Coverage-Guided Mutation: When a generated query triggers a previously unexplored path in the database's code, ParserFuzz saves that query's syntax tree in a fuzzing queue. It then mutates these "interesting" trees by swapping branches with new segments generated from the grammar, effectively "learning" which syntax combinations reach deeper into the database logic.
  4. Query Instantiation: To ensure queries are semantically plausible, ParserFuzz includes a validity-oriented instantiation phase that populates the generated structures with concrete data and identifiers.

Experimental Evaluation

We evaluated ParserFuzz against five major open-source DBMSs: MySQL, SQLite, CockroachDB, TiDB, and MariaDB. The tool was compared against industry-standard baselines, including SQLsmith, Squirrel, SQLancer, and general-purpose fuzzers like AFL++.

Key Results

  • Bug Discovery: ParserFuzz discovered 81 previously unknown bugs, including 29 segmentation faults and 52 assertion failures. At the time of publication, 34 of these bugs had already been confirmed and fixed by the respective development teams.
  • Superior Coverage: In 24-hour head-to-head tests, ParserFuzz consistently outperformed Squirrel and SQLsmith in terms of code coverage and the exploration of unique grammar edges.
  • Real-World Impact: The tool uncovered a complex bug in MySQL involving a rare combination of "normal" and "functional" indexes in a temporary table. This scenario was so specific that it was absent from MySQL's official unit tests and had been missed by all previous fuzzing tools.

Conclusion

ParserFuzz demonstrates that the parser itself is the best specification for testing a DBMS. By automating grammar extraction and employing coverage-guided feedback with strategic rule prioritization, ParserFuzz achieves high coverage and discovers critical bugs with zero initial seeds. Future work will focus on refining semantic awareness to reduce invalid query generation and expanding support for additional parser formats like ANTLR.

Summary updated

BibTeX
@misc{liang2025parser,
  author = {Yu Liang and Hong Hu},
  title = {{Parser Knows Best: Testing DBMS with Coverage-Guided Grammar-Rule Traversal}},
  year = {2025},
  eprint = {2503.03893},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2503.03893},
}
Figure