arXivDaily arXiv每日学术速递 周一至周五更新
arXiv周末暂无论文更新,休息一下吧,周末愉快~~
arXiv 2612.04539cs.DBcs.SE
收藏

ReGenSQL:结合遗传改进与大语言模型的混合查询重写框架

ReGenSQL: A Hybrid Query Rewrite Framework with Genetic Improvement and Large Language Models

University College London(伦敦大学学院);University of Edinburgh(爱丁堡大学)

Hassan Kandil, Carol Hanna, Justyna Petke

AI总结:

ReGenSQL是结合遗传改进与大语言模型的混合SQL查询重写框架,在TPC-H等基准测试中,其不同配置在效率与有效性上均优于基线及现有系统,具备良好可迁移性。

摘要:

优化SQL查询执行仍是关系数据库系统的核心挑战,因为语义等价的查询在运行时可能存在数个数量级的差异。传统优化器常出现成本估计错误,且无法探索全部转换空间;而近期基于大语言模型(LLM)的方法虽能生成有前景的重写结果,但通常仅停留在单个候选方案,缺乏系统性搜索。本研究提出ReGenSQL,这是一个将遗传改进(GI)与检索增强的LLM引导相结合的混合框架,以更有效地探索查询重写。ReGenSQL利用Apache Calcite的已验证转换规则确保语义正确性,使用R-Bot生成多样化的LLM驱动候选方案,并应用进化搜索基于估计或实际执行成本的适应度函数优化重写。在TPC-H基准上的评估表明,ReGenSQL在效率与有效性间实现了清晰的权衡:在以有效性为核心的场景中,采用执行延迟适应度的LLM+GI变体平均降低50.5%的执行时间,中位数延迟为39.7%、第75百分位延迟为91.0%,在查询覆盖率和改进数量上均超越现有最优系统;在以效率为核心的场景中,仅GI配置的平均重写延迟仅为5秒,比基线快近36倍,且无需LLM的计算与资金开销即可实现有竞争力的性能提升。在DSB和JOB上的评估进一步证明其可迁移性,ReGenSQL分别改进了高达50.0%和23.0%的查询,而基线仅为13.16%和3.54%。总体而言,研究结果表明仅GI就是一种强大的优化策略,LLM引导则提供了情境化优势,使ReGenSQL成为一种稳健且适应性强的SQL查询重写方法。

英文摘要:

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.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑