A curated list of papers, systems, benchmarks, and best practices for SQL query rewriting.
This repository focuses on semantically equivalent SQL transformations that improve execution efficiency and reliability, including rule-based rewriting, learned rewriting, and LLM-assisted rewriting.
- Papers
- Recommended Taxonomy
- Systems and Tools
- Benchmarks and Workloads
- Evaluation and Methodology
- Contribution Guide
| Year | Title | Venue | Paper | Code | Category | Notes |
|---|---|---|---|---|---|---|
| 2026 | Efficient Query Rewrite Rule Discovery via Standardized Enumeration and Learning-to-Rank (extend) | arXiv preprint (cs.DB) | arXiv | - | Automatic rule discovery | SLER combines template enumeration with learning-to-rank and reports a million-scale verified rule library. |
| 2026 | LASER: A Data-Centric Method for Low-Cost and Efficient SQL Rewriting based on SQL-GRPO | arXiv preprint (cs.DB) | arXiv | GitHub | LLM + RL rewriting | Introduces SQL-MCTS slow-query corpus and SQL-GRPO alignment for low-cost rewrite generation. |
| 2026 | Leveraging Query Optimizers to Verify the Soundness of LLM-based Query Rewrites for Real-World Workloads, and More! | CIDR 2026 | - | Soundness and verification | Proposes QO-Verify to check rewrite soundness using optimizer internals on benchmark and real enterprise workloads. |
| Year | Title | Venue | Paper | Code | Category | Notes |
|---|---|---|---|---|---|---|
| 2025 | GRewriter: Practical Query Rewriting with Automatic Rule Set Expansion in GaussDB | PVLDB 18(12):4991-5003 | PDF / DOI | - | Production rule engine | A bolt-on extensible rewriter integrated into GaussDB with automated rule generation and production deployment results. |
| 2025 | QUITE: A Query Rewrite System Beyond Rules with LLM Agents | arXiv preprint (cs.DB/cs.AI) | arXiv | GitHub | Agentic LLM rewriting | Uses multi-agent LLM workflow to go beyond fixed rule sets and reduce regressions from rigid heuristics. |
| 2025 | Query Rewriting via LLMs | arXiv preprint (cs.DB) | arXiv | - | LLM-assisted rewriting | Studies prompt ensembles, database-sensitive hints, and token-probability guidance for performant and correct rewrites. |
| Year | Title | Venue | Paper | Code | Category | Notes |
|---|---|---|---|---|---|---|
| 2024 | Learned Graph Rewriting with Equality Saturation: A New Paradigm in Relational Query Rewrite and Beyond | arXiv preprint (cs.DB/cs.LG) | arXiv | - | Learned graph rewriting | Combines equality saturation with graph RL for relational rewrite search. |
| 2024 | LLM-R2: A Large Language Model Enhanced Rule-based Rewrite System for Boosting Query Efficiency | arXiv preprint (cs.DB/cs.CL) | arXiv | GitHub | LLM-enhanced rule system | Uses LLMs to propose rewrite rules and contrastive selection to improve rule recommendation quality. |
| Year | Title | Venue | Paper | Code | Category | Notes |
|---|---|---|---|---|---|---|
| 2023 | A Learned Query Rewrite System | PVLDB 16(12):4110-4113 | PDF / DOI | GitHub | Learned rewrite system demo | Demonstrates a practical LearnedRewrite pipeline over Calcite with MCTS and hybrid estimation. |
| 2023 | QueryBooster: Improving SQL Performance Using Middleware Services for Human-Centered Query Rewriting | arXiv preprint (cs.DB) | arXiv | GitHub | Human-in-the-loop rewriting | Presents middleware-driven, user-oriented SQL rewrite assistance when DB/application internals are black-boxed. |
| Year | Title | Venue | Paper | Code | Category | Notes |
|---|---|---|---|---|---|---|
| 2022 | A Learned Query Rewrite System using Monte Carlo Tree Search | PVLDB 15(1):46-58 | PDF / DOI | GitHub | Learned search | Models rewrite orders as a policy tree and uses MCTS plus learned estimators to find high-benefit rewrite sequences. |
| 2022 | WeTune: Automatic Discovery and Verification of Query Rewrite Rules | SIGMOD 2022 | DOI | - | Automatic rule discovery | Automatically discovers and verifies rewrite rules from real SQL workloads and known anti-patterns. |
To keep this repository future-proof, we recommend organizing query rewrite research using five categories instead of only "rule-based vs LLM":
Rule-based / Heuristic Rewriting: Manual rules and fixed exploration orders inside query optimizers.Automatic Rule Discovery & Learned Search: Automatically mined rules and learned strategies for rewrite-order exploration.LLM-Enhanced Rule Systems: LLMs assist with rule proposal, ranking, or selection while execution stays rule-engine driven.LLM-Direct / Agentic Rewriting: LLMs or agents directly generate rewritten SQL with runtime feedback loops.Soundness & Verification: Methods focused on semantic-equivalence checks, guardrails, and regression prevention.
- Apache Calcite - Foundational framework for SQL parsing, relational algebra, and rule-based optimization.
- SQLGlot - SQL parser/transpiler with optimizer utilities useful for rewrite experimentation.
- LearnedRewrite - Research implementation for learned SQL rewrite search.
- TPC-H - Widely used analytic benchmark for SQL performance studies.
- TPC-DS - Decision-support benchmark with complex SQL templates.
- Join Order Benchmark (JOB) - Realistic multi-join workload often used in optimizer and rewrite studies.
- SQL-MCTS (introduced in LASER) - A slow-query corpus designed for LLM-oriented rewriting research.
Recommended minimum reporting dimensions for each paper/system:
- Semantic correctness checks: result-equivalence rate and failure taxonomy.
- Performance gains: latency speedup distribution (median, p90/p99) and tail regressions.
- Rewrite overhead: rewrite-time/optimization-time overhead and search cost.
- Generalization: cross-workload and cross-engine robustness.
- Safety: rate of harmful rewrites, rollback strategy, and verification coverage.
- Practicality: deployment constraints (privacy, token cost, integration complexity).
Please read CONTRIBUTING.md before submitting.
Quick rules:
- Keep entries concise and source-verifiable.
- Add year and venue for every paper.
- Prefer primary links (official venue or arXiv).
- Keep year sections in descending order and entries alphabetically sorted within each year.