paper-with-me

홈 › Papers

E3-Rewrite: Learning to Rewrite SQL for Executability, Equivalence,and Efficiency

2025-08-12 · Dongjie Xu, Yue Cui, Weijie Shi, Qingzhi Ma, Hanghui Guo, Jiaming Li, Yao Zhao, Ruiyuan Zhang, Shimin Di, Jia Zhu, Kai Zheng, Jiajie Xu arxiv

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, equivalent, and efficient queries. It integrates two core components: a context construction module and a reinforcement learning framework. First, the context module leverages execution plans and retrieved demonstrations to build bottleneck-aware prompts that guide inference-time rewriting. Second, we design a reward function targeting executability, equivalence, and efficiency, evaluated via syntax checks, equivalence verification, and cost estimation. Third, to ensure stable multi-objective learning, we adopt a staged curriculum that first emphasizes executability and equivalence, then gradually incorporates efficiency. Across multiple SQL benchmarks, our experiments demonstrate that E3-Rewrite can shorten query execution time by as much as 25.6% relative to leading baselines, while also producing up to 24.4% more rewrites that meet strict equivalence criteria. These gains extend to challenging query patterns that prior approaches could not effectively optimize.

📄 PDF Abstract BibTeX arXiv:2508.09023

Code (0)

등록된 구현이 없습니다.

Tasks

Reinforcement Learning

Similar Papers 제목 키워드 기반

LLM-R2: A Large Language Model Enhanced Rule-based Rewrite System for Boosting Query Efficiency

2024-04-19 · Zhaodonghui Li, Haitao Yuan, Huiming Wang, Gao Cong 외

Query rewrite, which aims to generate more efficient queries by altering a SQL query's structure without changing the query result, has been an important research problem. In order to maintain equivalence between the rew…

Language ModelingLanguage ModellingLarge Language Model

Equivalence of Dataflow Graphs via Rewrite Rules Using a Graph-to-Sequence Neural Model

2020-02-17 · Steve Kommrusch, Théo Barollet, Louis-Noël Pouchet

In this work we target the problem of provably computing the equivalence between two programs represented as dataflow graphs. To this end, we formalize the problem of equivalence between two programs as finding a set of …

Graph-to-Sequence

Proving Equivalence Between Complex Expressions Using Graph-to-Sequence Neural Models

2021-06-01 · Steve Kommrusch, Théo Barollet, Louis-Noël Pouchet

We target the problem of provably computing the equivalence between two complex expression trees. To this end, we formalize the problem of equivalence between two such programs as finding a set of semantics-preserving re…

Graph-to-Sequencevalid

Self-Supervised Learning to Prove Equivalence Between Straight-Line Programs via Rewrite Rules

2021-09-22 · Steve Kommrusch, Martin Monperrus, Louis-Noël Pouchet

We target the problem of automatically synthesizing proofs of semantic equivalence between two programs made of sequences of statements. We represent programs using abstract syntax trees (AST), where a given set of seman…

Self-Supervised Learningvalid

R-Bot: An LLM-based Query Rewrite System

2024-12-02 · Zhaoyan Sun, Xuanhe Zhou, Guoliang Li

Query rewrite is essential for optimizing SQL queries to improve their execution efficiency without changing their results. Traditionally, this task has been tackled through heuristic and learning-based methods, each wit…