arXiv · 2612.04539
ReGenSQL: A Hybrid Query Rewrite Framework with Genetic Improvement and Large Language Models
Abstract
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 state-of-the-art systems in both query coverage and number of improvements. In efficiency-focused settings, the GI-only configuration attains a mean rewrite latency of just 5s, nearly 36x faster than the baseline, while still delivering competitive performance gains without the computational and monetary overhead of LLMs. Evaluations on DSB and JOB further demonstrate transfer beyond TPC-H, with ReGenSQL improving up to 50.0% and 23.0% of queries, respectively, versus 13.16% and 3.54% for the baseline. Overall, our findings demonstrate that GI alone is a strong optimisation strategy and that LLM guidance provides situational benefits, making ReGenSQL a robust and adaptable approach to SQL query rewriting.
Explore related subjects
Keep this discovery
Explore connections, maps & timelines
Hassan Kandil, Carol Hanna, Justyna Petke. 2026-12-02. ReGenSQL: A Hybrid Query Rewrite Framework with Genetic Improvement and Large Language Models. https://searcharxiv.org/abs/2612.04539
Citations retain the original authors and DOI and include this site’s record URL. If this discovery service contributed to your research, you can also cite Search arXiv by Indiciae: BibTeX · RIS.