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
4/19/2024
cs.DBcs.CL

No official code found. Best implementation: DAMO-NLP-SG/LLM-R2 (56 stars, last commit 2024-11-26).

Abstract

Query rewrite, which aims to generate more efficient queries by altering a SQL query's structure without changing the query result, has been an important research problem. In order to maintain equivalence between the rewritten query and the original one during rewriting, traditional query rewrite methods always rewrite the queries following certain rewrite rules. However, some problems still remain. Firstly, existing methods of finding the optimal choice or sequence of rewrite rules are still limited and the process always costs a lot of resources. Methods involving discovering new rewrite rules typically require complicated proofs of structural logic or extensive user interactions. Secondly, current query rewrite methods usually rely highly on DBMS cost estimators which are often not accurate. In this paper, we address these problems by proposing a novel method of query rewrite named LLM-R2, adopting a large language model (LLM) to propose possible rewrite rules for a database rewrite system. To further improve the inference ability of LLM in recommending rewrite rules, we train a contrastive model by curriculum to learn query representations and select effective query demonstrations for the LLM. Experimental results have shown that our method can significantly improve the query execution efficiency and outperform the baseline methods. In addition, our method enjoys high robustness across different datasets.

View on arXivView PDF

Code Implementations(1)

DAMO-NLP-SG/LLM-R2Community100%
5613Java, ShellApr 3, 20241 years ago

Similar Papers

Cite this paper

@article{li2024llmr,
  title  = {LLM-R2: A Large Language Model Enhanced Rule-based Rewrite System for Boosting Query Efficiency},
  author = {Zhaodonghui Li and Haitao Yuan and Huiming Wang and Gao Cong and Lidong Bing},
  year   = {2024},
  eprint = {2404.12872},
  archivePrefix = {arXiv},
  url    = {http://arxiv.org/abs/2404.12872v1}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2404.12872.svg)](https://codeofpaper.com/paper/2404.12872)

Discussion