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

**Authors:** Zhaodonghui Li, Haitao Yuan, Huiming Wang, Gao Cong, Lidong Bing  
**arXiv:** [2404.12872](https://arxiv.org/abs/2404.12872)  
**Date:** 2024-04-19  
**Summary page:** https://www.summarizepaper.com/en/paper/2404.12872v1/

## Key points

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

## Summary

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.
