Lune

SIGMOD2026Top-tier venue

GenRewrite: Query Rewriting via Large Language Models

Jie Liu, Barzan Mozafari

Abstract

Query rewriting is an effective technique for refining poorly written queries before they reach the query optimizer. However, manual rewriting is not scalable, as it is prone to errors and requires deep expertise. Traditional query rewriting algorithms fall short too: rule-based approaches fail to generalize to new query patterns, while synthesis-based methods struggle with complex queries. Fortunately, Large Language Models (LLMs) already possess broad knowledge and advanced reasoning capabilities, making them a promising solution for tackling these longstanding challenges.

In this paper, we present GenRewrite, the first holistic system that leverages LLMs for query rewriting beyond traditional rules. We introduce the notion of Natural Language Rewrite Rules (NLR2s), which serve as hints for the LLM while also a means of knowledge transfer from rewriting one query to another, allowing GenRewrite to become smarter and more effective over time. We present a novel counterexample-guided technique that iteratively corrects the syntactic and semantic errors in the rewritten query, significantly reducing the LLM costs and the manual effort required for verification. Across the standard TPC-DS [8] and JOB [25] benchmarks and their SQLStorm-generated variants [38], GenRewrite consistently optimizes more queries at every speedup threshold than all baselines. At the ≥2x threshold on TPC-DS, Gen-Rewrite improves 25 queries-1.35x more than LLM-driven baselines and 2.6x more than LLM-enhanced rule-based baselines-and the gap widens further on TPC-DS (SQLStorm); on JOB and its SQLStorm variant, where queries are simpler, absolute gains are smaller but GenRewrite still leads by a notable margin.

Ask Lune

Know this paper in minutes, not an afternoon.

Lune can read every page of it and the top-tier papers that cite it, and gives you its claims, its evidence and its limits, each one cited to the paper it comes from. No skimming, no AI slop.

5 top-tier papers have cited it since. Know what they found before your reviewers do.

Questions to start from

Lune can draw on

the full paper · the top-tier papers that cite it · related work

Get the answer

Free to start. No credit card required.

Lineage

  • AgentTune: An Agent-Based Large Language Model Framework for Database Knob Tuning cites DIN-SQL: Decomposed In-Context Learning of Text-to-SQL with Self-Correction
  • AgentTune: An Agent-Based Large Language Model Framework for Database Knob Tuning cites Text-to-SQL Empowered by Large Language Models: A Benchmark Evaluation
  • Text-to-SQL Empowered by Large Language Models: A Benchmark Evaluation cites DIN-SQL: Decomposed In-Context Learning of Text-to-SQL with Self-Correction
  • Cracking SQL Barriers: An LLM-based Dialect Translation System cites A Learned Query Rewrite System using Monte Carlo Tree Search
  • Efficient Query Rewrite Rule Discovery via Standardized Enumeration and Learning-to-Rank cites A Learned Query Rewrite System using Monte Carlo Tree Search
  • ReSequel: Robust LLM-assisted Query Rewriting and Optimization using Templatization and Sampling cites A Learned Query Rewrite System using Monte Carlo Tree Search
Builds onCited byLeft to right by year; the more cited, the higher.

Cited by top-tier papers5

  1. Cracking SQL Barriers: An LLM-based Dialect Translation SystemWei Zhou, Yuyang Gao, Xuanhe Zhou, Guoliang LiSIGMOD 2025 · 14 citations
  2. AgentTune: An Agent-Based Large Language Model Framework for Database Knob TuningYiyan Li, Haoyang Li, Jing Zhang, Renata Borovica-Gajic et al.SIGMOD 2026 · 5 citations
  3. Suit the Remedy to the Retriever: Interpretable Query Optimization with Retriever Preference Alignment for Vision-Language RetrievalGuanghao Meng, Jinpeng Wang, Jieming Zhu, Letian Zhang et al.AAAI 2026
  4. Efficient Query Rewrite Rule Discovery via Standardized Enumeration and Learning-to-RankYuan Zhang, Yuxing Chen, Yuekun Yu, Jinbin Huang et al.ICDE 2026
  5. ReSequel: Robust LLM-assisted Query Rewriting and Optimization using Templatization and SamplingSaeed Fathollahzadeh, Essam Mansour, Matthias BoehmVLDB 2026

Builds on15

  1. DIN-SQL: Decomposed In-Context Learning of Text-to-SQL with Self-CorrectionMohammadreza Pourreza, Davood RafieiNeurIPS 2023 · 909 citations
  2. Text-to-SQL Empowered by Large Language Models: A Benchmark EvaluationDawei Gao, Haibin Wang, Yaliang Li, Xiuyu Sun et al.VLDB 2024 · 609 citations
  3. Can Foundation Models Wrangle Your Data?Avanika Narayan, Ines Chami, Laurel J. Orr, Christopher RéVLDB 2023 · 325 citations
  4. A Learned Query Rewrite System using Monte Carlo Tree SearchXuanhe Zhou, Guoliang Li, Chengliang Chai, Jianhua FengVLDB 2022 · 85 citations
  5. Annotating Columns with Pre-trained Language ModelsYoshihiko Suhara, Jinfeng Li, Yuliang Li, Dan Zhang et al.SIGMOD 2022 · 81 citations

Related papers

  1. LLM-R2: A Large Language Model Enhanced Rule-based Rewrite System for Boosting Query EfficiencyZhaodonghui Li, Haitao Yuan, Huiming Wang, Gao Cong et al.VLDB 2025 · 52 citations
  2. CHIQ: Contextual History Enhancement for Improving Query Rewriting in Conversational SearchFengran Mo, Abbas Ghaddar, Kelong Mao, Mehdi Rezagholizadeh et al.EMNLP 2024 · 9 citations
  3. Think Then Rewrite: Reasoning Enhanced Query Rewriting for Domain Specific RetrievalAng Li, Yufei Shi, Yuxuan Si, Yiquan Wu et al.AAAI 2026
  4. Enhancing Conversational Search: Large Language Model-Aided Informative Query RewritingFanghua Ye, Meng Fang, Shenghui Li, Emine YilmazEMNLP Findings 2023 · 35 citations
  5. Generalized Pseudo-Relevance FeedbackYiteng Tu, Weihang Su, Yujia Zhou, Yiqun Liu et al.WWW 2026 · 2 citations
Dusk over the sea between two cliffs drawn in fine vertical lines