SQL query rewriting is a well-established technique for improving database performance without schema or index changes, yet finding effective rewrites for modern analytical workloads remains difficult: rule-based methods are limited to predefined transformations, while LLM-based approaches often produce rewrites that are semantically valid but compile to equivalent physical plans or degrade runtime performance. We present SPA, a SQL-Plan-Aware reinforcement learning framework that trains LLMs to rewrite queries using physical execution feedback. SPA formulates rewriting as a policy optimization problem and extends GRPO with rewards spanning semantic equivalence, textual rewrite distance, physical-plan divergence, and runtime speedup. To handle reward sparsity across query difficulty, SPA introduces Probability-Gated Adaptive Reward Shaping, a query-level curriculum that unlocks higher-level rewards only once a rollout group achieves sufficient mastery of lower-level objectives, and further improves sample efficiency through on-policy self-improvement by recycling slowdown rewrites from the current policy as targeted training signals. On both IID and OOD workloads, SPA outperforms rule-based and strong LLM baselines in end-to-end runtime, substantially reduces harmful slowdown rewrites, and yields strong tail-latency gains.


翻译:SQL查询重写是一种在不更改模式或索引的情况下提升数据库性能的成熟技术,然而为现代分析型负载找到有效的重写方案仍面临挑战:基于规则的方法局限于预定义变换,而基于大语言模型的方法生成的重写结果虽语义正确,却可能编译为等效的物理计划或导致运行时性能退化。本文提出SPA——一种基于SQL-计划感知的强化学习框架,通过物理执行反馈训练大语言模型进行查询重写。SPA将重写形式化为策略优化问题,并扩展GRPO算法,引入涵盖语义等价性、文本重写距离、物理计划差异及运行时加速的奖励机制。为应对不同查询难度下的奖励稀疏性,SPA提出概率门控自适应奖励塑形——一种查询级课程学习策略:只有当生成组在低层级目标上达到足够熟练度时,才解锁高层级奖励。此外,SPA通过基于当前策略的"减速重写"回收作为针对性训练信号,实现策略内自我改进以提升样本效率。在独立同分布与非独立同分布工作负载上,SPA在端到端运行时性能上超越基于规则的基线方法与强基准大语言模型,显著减少有害的减速重写,并在尾部延迟方面实现显著改进。

0
下载
关闭预览

相关内容

SQL 全名是结构化查询语言,是用于数据库中的标准数据查询语言,IBM 公司最早使用在其开发的数据库系统中。
智能数据库学习型索引研究综述
专知会员服务
23+阅读 · 2023年1月14日
「基于深度学习的 SQL 生成」2022研究综述
专知会员服务
28+阅读 · 2022年8月12日
可解释强化学习,Explainable Reinforcement Learning: A Survey
专知会员服务
132+阅读 · 2020年5月14日
Query 理解和语义召回在知乎搜索中的应用
DataFunTalk
25+阅读 · 2020年1月2日
工行基于MySQL构建分布式架构的转型之路
炼数成金订阅号
15+阅读 · 2019年5月16日
强化学习的Unsupervised Meta-Learning
CreateAMind
18+阅读 · 2019年1月7日
一种关键字提取新方法
1号机器人网
21+阅读 · 2018年11月15日
国家自然科学基金
18+阅读 · 2017年12月31日
国家自然科学基金
40+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
1+阅读 · 2015年12月31日
国家自然科学基金
1+阅读 · 2015年12月31日
国家自然科学基金
5+阅读 · 2015年12月31日
国家自然科学基金
1+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2014年12月31日
国家自然科学基金
2+阅读 · 2014年12月31日
国家自然科学基金
0+阅读 · 2014年12月31日
VIP会员
最新内容
《通过小型无人机系统将情报能力“作战化”》
消耗优势:美军的“精确规模化”概念
专知会员服务
8+阅读 · 6月15日
《离线语言支持系统:面向空战战术决策》
专知会员服务
10+阅读 · 6月15日
相关基金
国家自然科学基金
18+阅读 · 2017年12月31日
国家自然科学基金
40+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
1+阅读 · 2015年12月31日
国家自然科学基金
1+阅读 · 2015年12月31日
国家自然科学基金
5+阅读 · 2015年12月31日
国家自然科学基金
1+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2014年12月31日
国家自然科学基金
2+阅读 · 2014年12月31日
国家自然科学基金
0+阅读 · 2014年12月31日
Top
微信扫码咨询专知VIP会员