AI summary · arXiv: 2404.12872v1 · cs.DB

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

Zhaodonghui Li, Haitao Yuan, Huiming Wang, Gao Cong, Lidong Bing
Original paper Submitted to arXiv on 19 Apr. 2024 12 pages License: NONEXCLUSIVE-DISTRIB 1.0

How to read this summary? Illustrated guide

The essentials

  • Query rewrite is essential for enhancing query efficiency in database optimization.
  • Traditional methods of query rewrite face challenges in finding the optimal sequence of rewrite rules.
  • LLM-R2 is a novel approach that leverages a large language model to suggest potential rewrite rules while maintaining query equivalence.
  • A contrastive model trained using curriculum learning enhances the inference capabilities of LLM in recommending rewrite rules.
  • Experimental results show that LLM-R2 significantly improves query execution efficiency compared to baseline methods and exhibits high robustness across various datasets.
  • Authors Zhaodonghui Li, Haitao Yuan, Huiming Wang, Gao Cong, and Lidong Bing have collaborated on developing an advanced rule-based rewrite system for boosting query efficiency.

Key points written by AI: they may contain errors, check them against the paper.

AI-generated keywords: Database query optimization Query rewrite LLM-R2 Large language model Curriculum learning

Read further

  • Comprehensive Summary
  • Layman's Summary
  • Blog article
  • Original abstract
In the realm of database query optimization, the process of query rewrite plays a crucial role in enhancing query efficiency. It involves restructuring SQL queries without altering their results. However, traditional methods of query rewrite often face challenges in finding the optimal sequence of rewrite rules, leading to resource-intensive processes. To address these issues, a novel approach named LLM-R2 has been proposed. This innovative method leverages a large language model (LLM) to suggest potential rewrite rules for database systems while maintaining equivalence between the original and rewritten queries during the optimization process. To enhance the inference capabilities of LLM in recommending rewrite rules, a contrastive model is trained using curriculum learning. This helps the system understand query representations and select effective query demonstrations. Experimental results have demonstrated the effectiveness of LLM-R2 in significantly improving query execution efficiency compared to baseline methods. Moreover, this approach exhibits high robustness across various datasets. The collaborative efforts of authors Zhaodonghui Li, Haitao Yuan, Huiming Wang, Gao Cong, and Lidong Bing have led to the development of an advanced rule-based rewrite system that holds promise for boosting query efficiency in database operations.

Was this synthesis useful?

Score: 0

Why do we need votes?

Votes are used to determine whether we need to re-run our summarizing tools. If the count reaches -10, our tools can be restarted.

Figures and plots

Ask about a figure by number or use its question button to request visual analysis. Up to two figures and four image panels per question. Values read from plots are approximate; check the original data.

AI assistant instructions?

Tools for this paper

Explain it differently 1 free rewrite left today
Save to a collection Group papers in collections to compare them, chat with them and export them. Continue with Google Create a free account Log in

Advanced tools Premium

For researchers who follow a field closely: citation alerts, journal-club slides, version comparison and Zotero export. Discover Premium

Zotero
Citation alerts Citation alerts guide

Papers around this one

See them on a map

Ranked by how close their title and abstract are to this paper’s. Select some to read them together.

Closest papers

  1. Very close Cites this paper
    GenRewrite: Query Rewriting via Large Language Models
    Jie Liu, Barzan Mozafari · 2024 · Proc. ACM Manag. Data · cited 27 times · Not summarized yet
    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 traditi…

  2. Very close Cites this paper Uses this paper in depth
    QUITE: A Query Rewrite System Beyond Rules with LLM Agents
    Yu-Yang Song, Han-Xu Yan, Jia-Le Lao et al. · 2025 · arXiv.org · preprint, not peer reviewed · cited 20 times · Not summarized yet
    Abstract

    Query rewrite transforms SQL queries into semantically equivalent forms that run more efficiently. Existing approaches mainly rely on predefined rewrite rules, but they handle a limited subset of queries and can cause performance regressions. This limitation stems from three challenges of rule-based query rewrite: (1) it is hard to discover and verify new rules, (2) fixed rewrite rules do not generalize to new query patterns, and (3) some rewrite techniques cannot be expressed as fixed rules. Motivated by the fact that human experts exhibit significantly better rewrite ability but suffer from scalability, and Large Language Models (LLMs) have demonstrated nearly human-level semantic and reas…

  3. Very close Cites this paper Uses this paper in depth
    E3-Rewrite: Learning to Rewrite SQL for Executability, Equivalence,and Efficiency
    Dong Xu, Yue Cui, Wei-Jie Shi et al. · 2025 · arXiv.org · preprint, not peer reviewed · cited 7 times · Not summarized yet
    Abstract

    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-equ…

  4. Very close
    Enhancing Conversational Search: Large Language Model-Aided Informative Query Rewriting
    Fanghua Ye, Meng Fang, Shenghui Li et al. · 2023 · Human-Computer Interaction · cited 125 times · AI summary available
    Abstract

    Query rewriting plays a vital role in enhancing conversational search by transforming context-dependent user queries into standalone forms. Existing approaches primarily leverage human-rewritten queries as labels to train query rewriting models. However, human rewrites may lack sufficient information for optimal retrieval performance. To overcome this limitation, we propose utilizing large language models (LLMs) as query rewriters, enabling the generation of informative query rewrites through well-designed instructions. We define four essential properties for well-formed rewrites and incorporate all of them into the instruction. In addition, we introduce the role of rewrite editors for LLMs …

  5. Very close Cites this paper
    Query Rewriting via LLMs
    Sriram Dharwada, Himanshu Devrani, J. Haritsa et al. · 2025 · arXiv.org · preprint, not peer reviewed · cited 10 times · Not summarized yet
    Abstract

    When complex SQL queries suffer slow executions despite query optimization, DBAs typically invoke automated query rewriting tools to recommend ``lean''equivalents that are conducive to faster execution. The rewritings are usually achieved via transformation rules, but these rules are limited in scope and difficult to update in a production system. Recently, LLM-based techniques have also been suggested, but they are prone to semantic and syntactic errors. We investigate here how the remarkable cognitive capabilities of LLMs can be leveraged for performant query rewriting while incorporating safeguards and optimizations to ensure correctness and efficiency. Our study shows that these goals ca…

  6. Very close Cites this paper
    R-Bot: An LLM-based Query Rewrite System
    Zhaoyan Sun, Xuan-He Zhou, Guo-Liang Li et al. · 2024 · Proceedings of the VLDB Endowment · cited 55 times · Not summarized yet
    Abstract

    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 with its limitations in terms of inferior quality and low robustness. Recent advancements in LLMs offer a new paradigm by leveraging their superior natural language and code comprehension abilities. Despite their potential, directly applying LLMs like GPT-4 has faced challenges due to problems such as hallucinations, where the model might generate inaccurate or irrelevant results. To address this, we propose R-Bot , an LLM-based query rewrite system with a systematic approach. W…

  7. Very close Cites this paper
    LLM-MVs: An LLM-Enhanced Materialized Views-Based Query Rewriting System
    Chong Sun, Hao Hu, Huili Zhang et al. · 2025 · IEEE International Conference on e-Business Engineering · Not summarized yet
    Abstract

    Query rewriting, which aims to enhance query efficiency by modifying the structure of SQL queries without altering their results, stands as one of the pivotal research directions in the database domain. Traditional query rewriting approaches perform language-equivalent transformations based on manually predefined rewriting rules, thereby failing to fully harness the potential of Materialized Views (MVs) for query optimization. Furthermore, with the emergence of Large Language Models (LLMs), natural language interaction with LLMs can better unlock the potential of MVs in query rewriting. Nevertheless, the direct application of LLMs for query rewriting exhibits several limitations, including o…

  8. Very close Cites this paper
    ReSequel: Robust LLM-assisted Query Rewriting and Optimization using Templatization and Sampling
    Saeed Fathollahzadeh, Essam Mansour, Matthias Boehm · 2026 · Proceedings of the VLDB Endowment · Not summarized yet
    Abstract

    Heuristic query rewriting has long complemented cost-based optimization to improve performance. Such rewrites transform SQL queries into semantically equivalent forms that are easier or faster to execute. Examples are standardizing expressions, eliminating redundancy, propagating constants, pushing down selections and projections, unnesting queries, and utilizing constraints. Modern DBMSs implement hundreds to thousands of such rules, but maintaining them is notoriously difficult. The interactions among rules are complex, and their static nature and application order prevent adaptation to specific query and database characteristics. Recent approaches that use large language models (LLMs) for…

Prior work it builds on

  1. Close Used in depth by this paper
    A Learned Query Rewrite System using Monte Carlo Tree Search
    Xuan-He Zhou, Guo-Liang Li, Cheng-Liang Chai et al. · 2021 · Proceedings of the VLDB Endowment · cited 97 times · Not summarized yet
    Abstract

    Query rewrite transforms a SQL query into an equivalent one but with higher performance. However, SQL rewrite is an NP-hard problem, and existing approaches adopt heuristics to rewrite the queries. These heuristics have two main limitations. First, the order of applying different rewrite rules significantly affects the query performance. However, the search space of all possible rewrite orders grows exponentially with the number of query operators and rules and it is rather hard to find the optimal rewrite order. Existing methods apply a pre-defined order to rewrite queries and will fall in a local optimum. Second, different rewrite rules have different benefits for different queries. Existi…

  2. Close
    WeTune: Automatic Discovery and Verification of Query Rewrite Rules
    Zhao-Guo Wang, Zhou Zhou, Yicun Yang et al. · 2022 · SIGMOD Conference · cited 67 times · Not summarized yet
    Abstract

    Query rewriting transforms a relational database query into an equivalent but more efficient one, which is crucial for the performance of database-backed applications. Such rewriting relies on pre-specified rewrite rules. In existing systems, these rewrite rules are discovered through manual insights and accumulate slowly over the years. In this paper, we present WeTune, a rule generator that automatically discovers new rewrite rules. Inspired by compiler superoptimization, WeTune enumerates all valid logical query plans up to a certain size and tries to discover equivalent plans that could potentially lead to more efficient rewrites. The core challenge is to determine which set of condition…

  3. Close*
    SQL-PaLM: Improved Large Language Model Adaptation for Text-to-SQL
    Ruoxi Sun, Sercan Ö. Arik, Alex Muzio et al. · 2024 · Trans. Mach. Learn. Res. · cited 111 times · Not summarized yet
  4. Related Used in depth by this paper
    Can LLM Already Serve as A Database Interface? A BIg Bench for Large-Scale Database Grounded Text-to-SQLs
    Jinyang Li, Binyuan Hui, Ge Qu et al. · 2023 · Neural Information Processing Systems · cited 1,358 times · AI summary available
    Abstract

    Text-to-SQL parsing, which aims at converting natural language instructions into executable SQLs, has gained increasing attention in recent years. In particular, Codex and ChatGPT have shown impressive results in this task. However, most of the prevalent benchmarks, i.e., Spider, and WikiSQL, focus on database schema with few rows of database contents leaving the gap between academic study and real-world applications. To mitigate this gap, we present Bird, a big benchmark for large-scale database grounded in text-to-SQL tasks, containing 12,751 pairs of text-to-SQL data and 95 databases with a total size of 33.4 GB, spanning 37 professional domains. Our emphasis on database values highlights…

  5. Close
    ReAct: Synergizing Reasoning and Acting in Language Models
    Shunyu Yao, Jeffrey Zhao, Dian Yu et al. · 2022 · International Conference on Learning Representations · cited 13,359 times · Not summarized yet
    Abstract

    While large language models (LLMs) have demonstrated impressive capabilities across tasks in language understanding and interactive decision making, their abilities for reasoning (e.g. chain-of-thought prompting) and acting (e.g. action plan generation) have primarily been studied as separate topics. In this paper, we explore the use of LLMs to generate both reasoning traces and task-specific actions in an interleaved manner, allowing for greater synergy between the two: reasoning traces help the model induce, track, and update action plans as well as handle exceptions, while actions allow it to interface with external sources, such as knowledge bases or environments, to gather additional in…

Papers that cite it

  1. Close Uses this paper in depth
    Large Language Models in Database Management System Optimization: A Survey
    Sikha S. Bagui, M. Malagutti, Riccardo Morelli et al. · 2026 · ACM Transactions on Intelligent Systems and Technology · cited 2 times · Not summarized yet
    Abstract

    Large language models have demonstrated remarkable capabilities in reasoning, code generation, and knowledge integration, making them increasingly relevant across a range of data-intensive applications. Their potential to interpret natural language, synthesize domain knowledge, and adapt to complex tasks has recently motivated research on their use within database management systems to enhance performance and automation. This survey reviews how these models have been employed to support core optimization tasks in modern databases, including query processing, system tuning, indexing, and performance diagnostics. We examine the methodological foundations, such as fine-tuning and RAG, and analy…

  2. Close
    SPA: A SQL-Plan-Aware Reinforcement Learning Framework for Query Rewriting with LLMs
    Xin-Yi Huang, Zheng-Jie Miao · 2026 · arXiv.org · preprint, not peer reviewed · cited 1 time · Not summarized yet
    Abstract

    SQL query rewriting is a well-established technique for improving database performance without schema or index changes, yet finding effective rewrites for modern analytical workloads remains difficult: rule-based methods are limited to predefined transformations, while LLM-based approaches often produce rewrites that are semantically valid but compile to equivalent physical plans or degrade runtime performance. We present SPA, a SQL-Plan-Aware reinforcement learning framework that trains LLMs to rewrite queries using physical execution feedback. SPA formulates rewriting as a policy optimization problem and extends GRPO with rewards spanning semantic equivalence, textual rewrite distance, phy…

  3. Close
    Cracking SQL Barriers: An LLM-based Dialect Translation System
    Wei Zhou, Yu-Yang Gao, Xuan-He Zhou et al. · 2025 · Proc. ACM Manag. Data · cited 26 times · Not summarized yet
    Abstract

    Automatic dialect translation reduces the complexity of database migration, which is crucial for applications interacting with multiple database systems. However, rule-based translation tools (e.g., SQLGlot, jOOQ, SQLines) are labor-intensive to develop and often (1) fail to translate certain operations, (2) produce incorrect translations due to rule deficiencies, and (3) generate translations compatible with some database versions but not the others. In this paper, we investigate the problem of automating dialect translation with large language models (LLMs). There are three main challenges. First, queries often involve lengthy content (e.g., excessive column values) and multiple syntax ele…

  4. Close
    Training-Free Query Optimization via LLM-Based Plan Similarity
    Nikita K. Vasilenko, Alexander Demin, Vladimir Boorlakov · 2025 · The Bulletin of Irkutsk State University. Series Mathematics · cited 2 times · Not summarized yet
    Abstract

    Large language model (LLM) embeddings offer a promising new avenue for database query optimization. In this paper, we explore how pre-trained execution plan embeddings can guide SQL query execution without the need for additional model training. We introduce LLM-based Plan Mapping (LLM-PM), a framework that embeds the default execution plan of a query, finds its k nearest neighbors among previously executed plans, and recommends database hintsets based on neighborhood voting. A lightweight consistency check validates the selected hint, while a fallback mechanism searches the full hint space when needed. Evaluated on the JOB-CEB benchmark using openGauss, LLM-PM achieves an average 21% reduct…

  5. Close
    SQLBarber: A System Leveraging Large Language Models to Generate Customized and Realistic SQL Workloads
    Jia-Le Lao, Immanuel Trummer · 2025 · Proc. ACM Manag. Data · cited 12 times · Not summarized yet
    Abstract

    Database research and development often require a large number of SQL queries for benchmarking purposes. However, acquiring real-world SQL queries is challenging due to privacy concerns, and existing generation methods offer limited options for customization and for satisfying realistic constraints. To address this issue, we present SQLBarber, a system based on Large Language Models (LLMs) to generate customized and realistic SQL workloads. SQLBarber (1) eliminates the need for users to manually craft SQL templates in advance, while providing the flexibility to accept natural language specifications to constrain SQL templates, (2) scales efficiently to generate large volumes of queries match…

How are these papers found?

We compare the title and abstract of this paper with those of every paper summarized on this site, and with the papers Semantic Scholar recommends, those it cites and those citing it (for a much-cited paper, its most recent citations and, from OpenAlex, the most cited ones). Among the prior work and the follow-ups, the papers that use each other in depth, a method it uses and the much-cited follow-ups come a little higher. The levels (very close, close, related) come from the similarity of the texts, not from a judgment of quality; * marks a paper without an abstract, compared by its title. The sentence under a paper is written by an AI from the two abstracts: check it in the papers. A paper marked not relevant by three readers leaves the list.

Updated on 2 November 2026.

The previous summary was created more than a year ago and can be re-run (if necessary) by clicking on the Run button below.

Disclaimer: The AI-based summarization tool and virtual assistant provided on this website may not always provide accurate and complete summaries or responses. We encourage you to carefully review and evaluate the generated content to ensure its quality and relevance to your needs.