Skip to content

Latest commit

 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Awesome SQL Query Rewrite Awesome

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.

Contents

Papers

2026

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 PDF - Soundness and verification Proposes QO-Verify to check rewrite soundness using optimizer internals on benchmark and real enterprise workloads.

2025

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.

2024

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.

2023

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.

2022

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.

Recommended Taxonomy

To keep this repository future-proof, we recommend organizing query rewrite research using five categories instead of only "rule-based vs LLM":

  1. Rule-based / Heuristic Rewriting: Manual rules and fixed exploration orders inside query optimizers.
  2. Automatic Rule Discovery & Learned Search: Automatically mined rules and learned strategies for rewrite-order exploration.
  3. LLM-Enhanced Rule Systems: LLMs assist with rule proposal, ranking, or selection while execution stays rule-engine driven.
  4. LLM-Direct / Agentic Rewriting: LLMs or agents directly generate rewritten SQL with runtime feedback loops.
  5. Soundness & Verification: Methods focused on semantic-equivalence checks, guardrails, and regression prevention.

Systems and Tools

  • 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.

Benchmarks and Workloads

  • 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.

Evaluation and Methodology

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).

Contribution Guide

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.

About

A curated list of SQL query rewrite papers, tools, and benchmarks.

Resources

Contributing

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors