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

LLM-Based Test Case Generation in DBMS through Monte Carlo Tree Search

Yujia Chen, Yingli Zhou, Fangyuan Zhang, Cuiyun GaoarXiv 2026

TL;DR

The paper introduces MIST, a novel framework that combines Large Language Models (LLMs) with Monte Carlo Tree Search (MCTS) to automate test case generation for Database Management Systems (DBMSs). By pairing feature-guided, error-driven query synthesis with systematic MCTS-driven mutations, MIST overcomes the limitations of lightweight LLMs to significantly boost code coverage across diverse database dialects.

What Problem Does This Paper Address?

Database Management Systems (DBMSs) underpin modern data infrastructure, making their reliability paramount. Testing them thoroughly requires generating high-quality, syntactically valid, and semantically diverse SQL queries. Traditional automated testing methods (like fuzzing) require immense manual effort to craft grammar rules for different proprietary SQL dialects.

While Large Language Models (LLMs) offer a promising alternative for automated query generation, they hit two major roadblocks in industrial settings:

  1. Resource and Privacy Constraints: Organizations must use smaller, locally deployed LLMs (under 70B parameters) due to security concerns. These lightweight models often fail to grasp complex, proprietary SQL dialects, leading to syntax errors or overly simplistic queries.
  2. The Coverage Plateau: Standard LLM generation tends to produce highly repetitive queries that only test shallow execution paths, quickly stalling code coverage improvements.

Methods

To solve these challenges, the authors present MIST (LLM-based test case generation through Monte Carlo Tree Search), a two-stage framework:

  1. Stage I: Feature-Guided Error-Driven Test Case Synthetization: MIST extracts SQL features from official documentation to build a hierarchical feature tree. It then samples diverse feature combinations to prompt the LLM. Crucially, it maintains an "execution error memory"—if a generated query fails, the error feedback is fed back into subsequent prompts, helping the lightweight LLM learn dialect-specific constraints on the fly.
  2. Stage II: Monte Carlo Tree Search-Based Test Case Mutation: Once initial coverage gains plateau, MIST switches to an MCTS-driven mutation engine. It treats existing valid queries as "seeds" and uses MCTS to systematically select seeds and apply a curated set of 135 dialect-aware mutation rules (spanning DDL, DML, and DQL operations). The search is guided directly by code coverage rewards from the DBMS, pushing the testing into deeper, unexplored execution paths.
The two-stage MIST framework overview
Figure 5: Illustrating the MCTS for test case mutation.

Datasets

Instead of traditional machine learning datasets, the framework was evaluated by testing three widely used open-source DBMS architectures representing distinct designs:

  • DuckDB: An in-process analytical (OLAP) database.
  • PostgreSQL: A mature, client-server relational (OLTP) database.
  • SQLite: A lightweight, embedded transactional database.

The evaluation utilized four lightweight open-source LLMs: Qwen2.5-7B, Llama3.1-8B, Qwen2.5-14B, and Qwen2.5-32B.

Key Insights and Ideas

  • Prompting Beats Parameters: One of the most striking findings is that a smaller model (Qwen2.5-7B) equipped with MIST achieved higher line coverage on DuckDB (42.0%) than a much larger model (Qwen2.5-32B) using a standard baseline approach (25.8%). This proves that structured guidance and feedback loops are more critical than raw model capacity for domain-specific tasks.
  • Closed-Loop Error Learning: By saving execution errors into a memory module, the framework effectively creates an automated, localized fine-tuning effect via prompting, allowing lightweight models to overcome their lack of proprietary dialect training data.
  • The Power of MCTS in Fuzzing: Randomly mutating SQL queries often breaks syntax or semantic validity. Using MCTS ensures that mutations are optimized based on actual coverage rewards, balancing the exploration of new execution paths with the exploitation of high-performing seed queries.
  • Targeting the Optimizer: The Optimizer is notoriously the most complex component of a DBMS. MIST consistently achieved its highest absolute coverage values in the Optimizer module, showing that feature-guided diversity successfully triggers intricate query planning logic.

Key Results

MIST was compared against Fuzz4All, a state-of-the-art universal LLM-based fuzzer. Across all tested DBMSs and LLMs, MIST delivered substantial improvements:

  • Overall Coverage Boost: Achieved average relative improvements of 43.3% in line coverage, 32.3% in function coverage, and 46.4% in branch coverage compared to the baseline approach.
  • Module-Level Success: In the highly complex Optimizer module, MIST reached an impressive absolute line coverage of 67.9% for DuckDB and 60.6% for PostgreSQL on average.
  • Consistency: The performance gains were robust across all model sizes and database architectures, confirming MIST's strong generalization capabilities.
Table 1: Overall code coverage comparison between baseline and MIST.

Limitations and Future Work

  • Implicit Oracle Limitation: MIST relies on an implicit test oracle, meaning it considers a test case successful if it runs without crashing, throwing runtime exceptions, or causing syntax errors. It cannot currently detect logical bugs (where a query runs successfully but returns incorrect data).
  • Manual Feature Tree Construction: Building the initial hierarchical feature tree from official documentation takes about 6–8 hours per DBMS. While this is a one-time cost per database version, automating this extraction process would improve scalability.
  • Future Directions: The authors plan to extend MIST to additional database systems, investigate more sophisticated mutation strategies, and evaluate its explicit fault-finding effectiveness through mutation testing.

Summary updated

BibTeX
@misc{chen2026llm,
  author = {Yujia Chen and Yingli Zhou and Fangyuan Zhang and Cuiyun Gao},
  title = {{LLM-Based Test Case Generation in DBMS through Monte Carlo Tree Search}},
  year = {2026},
  eprint = {2603.21530},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2603.21530},
}
Figure