mlsanityData to 14 Oct 2026

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

arXiv 2508.09023 ↗First posted 12 Aug 2025cs.DB cs.AI cs.CLcited by 1

Not on the map. Why?

Abstract (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.

Key facts. Cited by 1 paper in the map (data through 14 Oct 2026). Builds on 10 of its 21 references that are in the map. First posted on arXiv 12 Aug 2025.

Builds on

10 of 21 references.

References · 10

  1. 2017Proximal Policy Optimization Algorithmscited by 15,215
  2. 2019Sentence-BERT: Sentence Embeddings using Siamese BERT-Networkscited by 9,170
  3. 2023Can LLM Already Serve as A Database Interface? A BIg Bench for Large-Scale Database Grounded Text-to-SQLscited by 688
  4. 2023DIN-SQL: Decomposed In-Context Learning of Text-to-SQL with Self-Correctioncited by 477
  5. 2025RAG-RL: Advancing Retrieval-Augmented Generation via RL and Curriculum Learningcited by 30
  6. 2024LLM-R2: A Large Language Model Enhanced Rule-based Rewrite System for Boosting Query Efficiencycited by 16
  7. 2024R-Bot: An LLM-based Query Rewrite Systemcited by 16
  8. 2023Enhancing Text-to-SQL Translation for Financial System Designcited by 12
  9. 2025Improving Generalization in Intent Detection: GRPO with Reward-Based Curriculum Samplingcited by 12
  10. 2025QUITE: A Query Rewrite System Beyond Rules with LLM Agentscited by 8

Built on by

Cited by year

Citing papers per year: 2025: 1.

1 paper.

Similar, not cited

Close in wording, no citation either way

  1. 2025ReEx-SQL: Reasoning with Execution-Aware Reinforcement Learning for Text-to-SQL
  2. 2023Query Rewriting for Retrieval-Augmented Large Language Models
  3. 2024Learned Graph Rewriting with Equality Saturation: A New Paradigm in Relational Query Rewrite and Beyond
  4. 2026EvoSQL: Memory-Augmented Critic-Generator Co-Evolution for Text-to-SQL
  5. 2026ACTS-SQL: Agentic and Critic-Oriented Tree-Structured SQL Correctness with Large Language Models
  6. 2026Not All Queries Need Rewriting: When Prompt-Only LLM Refinement Helps and Hurts Dense Retrieval
  7. 2025RetrySQL: text-to-SQL training with retry data for self-correcting query generation
  8. 2026Rewrite What Matters: Adaptive Multilingual Query Rewriting for Reasoning via Agentic Reinforcement Learning