E3-Rewrite: Learning to Rewrite SQL for Executability, Equivalence,and Efficiency
Dongjie Xu, Yue Cui, Weijie Shi, Qingzhi Ma, Hanghui Guo, Jiaming Li, Yao Zhao, Ruiyuan Zhang, Shimin Di, Jia Zhu, Kai Zheng, Jiajie Xu

TL;DR
E3-Rewrite leverages large language models with a specialized framework to generate SQL rewrites that are executable, equivalent, and more efficient, outperforming rule-based methods on multiple benchmarks.
Contribution
The paper introduces E3-Rewrite, a novel LLM-based framework with context-aware prompts and reinforcement learning to improve SQL query rewriting beyond rule-based limitations.
Findings
Reduces query execution time by up to 25.6%
Produces 24.4% more equivalent rewrites
Effective on complex and novel query patterns
Abstract
SQL query rewriting aims to reformulate a query into a more efficient form while preserving equivalence. Most existing methods rely on predefined rewrite rules. However, such rule-based approaches face fundamental limitations: (1) fixed rule sets generalize poorly to novel query patterns and struggle with complex queries; (2) a wide range of effective rewriting strategies cannot be fully captured by declarative rules. To overcome these issues, we propose using large language models (LLMs) to generate rewrites. LLMs can capture complex strategies, such as evaluation reordering and CTE rewriting. Despite this potential, directly applying LLMs often results in performance regressions or non-equivalent rewrites due to a lack of execution awareness and semantic grounding. To address these challenges, We present E3-Rewrite, an LLM-based SQL rewriting framework that produces executable,…
Peer Reviews
No public reviews on file for this paper yet. If you reviewed it on a platform where reviews are public (OpenReview, ICLR, NeurIPS, ICML), you can paste yours below so the community can read it here.
Videos
No videos yet. Explain this paper in a talk, walkthrough, or lecture? Add one.
Taxonomy
TopicsAdvanced Database Systems and Queries · Scientific Computing and Data Management · Semantic Web and Ontologies
