ReGenSQL: A Hybrid Query Rewrite Framework with Genetic Improvement and Large Language Models
Optimising SQL query execution remains a core challenge in relational database systems, as semantically equivalent queries can differ in runtime by several orders of magnitude. Traditional optimisers often misestimate costs and fail to explore the full transformation space, while recent Large Language Model (LLM)-based approaches generate promising rewrites but typically settle on a single candidate without systematic search. This work presents ReGenSQL, a hybrid framework that integrates Genetic Improvement (GI) with retrieval-augmented LLM guidance to explore query rewrites more effectively. ReGenSQL leverages Apache Calcite's verified transformation rules to ensure semantic correctness, uses R-Bot to seed diverse LLM-informed candidates, and applies evolutionary search to refine rewrites under fitness functions based on either estimated or actual execution cost. Evaluation on the TPC-H benchmark demonstrates that ReGenSQL achieves a clear trade-off between efficiency and effectiveness. In effectiveness-focused settings, the LLM+GI variant with execution latency fitness reduces execution time by 50.5% on average, with 39.7% median and 91.0% 75th-percentile latency, surpassing…
- arXiv
- 2612.04539
- Authors
- Hassan Kandil, Carol Hanna, Justyna Petke
- Categories
- cs.DB · cs.SE