Abstract
Learned Cost Models (LCMs) are essential for optimizing query execution in composable data systems, yet they suffer from a significant "cold start" problem due to the scarcity of diverse, realistic training data. This paper presents DiGiT, a scalable Synthetic Data Generation (SDG) pipeline leveraging Large Language Models (LLMs) to produce high-quality SQL workloads. By employing few-shot prompting and subschema decomposition, DiGiT generates queries that better reflect real-world complexity than traditional mechanical generators. Experimental results demonstrate that LCMs trained on DiGiT-generated data achieve higher predictive accuracy with 45% fewer training samples, leading to a 10% reduction in total execution time for query routing tasks.
Introduction
In modern data architectures, a single SQL query may be executed across multiple engines such as Spark or Presto. Selecting the most efficient engine requires accurate Learned Cost Models (LCMs). However, training these models requires thousands of diverse SQL queries. Existing benchmarks like TPC-H are often too simplistic, and proprietary workloads are rarely accessible. Traditional "mechanical" query generators often produce repetitive patterns that fail to capture the nuances of human-written SQL, leading to poor model generalization.
Methodology: The DiGiT Pipeline
The researchers propose DiGiT, an LLM-driven "self-instruct" pipeline designed to generate complex and diverse synthetic SQL queries. Unlike purely algorithmic approaches, DiGiT utilizes the reasoning capabilities of LLMs (specifically IBM Granite-3.3-8b-instruct) to interpret database schemas and generate semantically meaningful queries.
The pipeline consists of four primary stages:
- Subschema Creation: To manage LLM context windows, the database schema is partitioned into logical subschemas based on foreign key relationships.
- Few-Shot Prompting: The LLM is provided with a subschema and a small set of "seed" examples to guide the generation of complex queries.
- Constraint Steering: Prompts can be augmented with specific constraints (e.g., requiring
GROUP BYorORDER BYclauses) to ensure coverage of specific SQL features. - Validation: A multi-stage validator ensures syntactic correctness, executability, and semantic consistency while filtering out redundant queries.
Experimental Evaluation
The study utilized the TPC-H schema to compare three datasets: a mechanical baseline (4,000 queries), an SDG dataset (2,200 queries), and an evaluation set (1,000 queries). The goal was to assess how well an LCM trained on these datasets could predict execution costs on Spark-SQL and PrestoDB.
Diversity and Runtime Distribution
A key finding was that LLM-generated queries exhibit a more uniform distribution of execution times and a richer variety of SQL operators compared to mechanical generators. This diversity allows the cost model to learn the underlying performance characteristics of the engine more effectively. Few-shot prompting (e.g., 3-shot) was found to produce more realistic and concise SQL than zero-shot approaches.
Results
The SDG-trained model outperformed the mechanical baseline across all key metrics. Despite using 45% fewer training samples, the SDG approach achieved a lower mean Q-error, indicating superior predictive accuracy.
In a practical query routing scenario, the SDG-trained model reduced total execution time for 1,000 test queries from 165 minutes to 150 minutes—a 10% performance improvement. This demonstrates that higher-quality synthetic data directly translates to better operational decisions in data systems.
Conclusion and Future Work
Bootstrapping LCMs with LLM-generated synthetic data effectively addresses the cold-start problem in query optimization. Future research will focus on automating metadata discovery to further reduce manual input and implementing a "closed-loop" reinforcement learning system. In such a system, the LCM's predictive failures would inform the SDG pipeline to generate targeted queries for the model's "blind spots," further refining accuracy.
Summary updated