R-Bot: An LLM-based Query Rewrite System

Fuente: arXiv
Saved in:
Bibliographic Details
Main Authors: Sun, Zhaoyan, Zhou, Xuanhe, Li, Guoliang, Yu, Xiang, Feng, Jianhua, Zhang, Yong
Format: Preprint
Published: 2024
Subjects:
Online Access:
Tags: Add Tag
No Tags, Be the first to tag this record!
_version_ 1866916854739501056
author Sun, Zhaoyan
Zhou, Xuanhe
Li, Guoliang
Yu, Xiang
Feng, Jianhua
Zhang, Yong
author_facet Sun, Zhaoyan
Zhou, Xuanhe
Li, Guoliang
Yu, Xiang
Feng, Jianhua
Zhang, Yong
contents 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. We first design a multi-source rewrite evidence preparation pipeline to generate query rewrite evidences for guiding LLMs to avoid hallucinations. We then propose a hybrid structure-semantics retrieval method that combines structural and semantic analysis to retrieve the most relevant rewrite evidences for effectively answering an online query. We next propose a step-by-step LLM rewrite method that iteratively leverages the retrieved evidences to select and arrange rewrite rules with self-reflection. We conduct comprehensive experiments on real-world datasets and widely used benchmarks, and demonstrate the superior performance of our system, R-Bot, surpassing state-of-the-art query rewrite methods. The R-Bot system has been deployed at Huawei and with real customers, and the results show that the proposed R-Bot system achieves lower query latency.
format Preprint
id arxiv_https___arxiv_org_abs_2412_01661
institution arXiv
publishDate 2024
record_format arxiv
spellingShingle R-Bot: An LLM-based Query Rewrite System
Sun, Zhaoyan
Zhou, Xuanhe
Li, Guoliang
Yu, Xiang
Feng, Jianhua
Zhang, Yong
Databases
Artificial Intelligence
Computation and Language
Machine Learning
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. We first design a multi-source rewrite evidence preparation pipeline to generate query rewrite evidences for guiding LLMs to avoid hallucinations. We then propose a hybrid structure-semantics retrieval method that combines structural and semantic analysis to retrieve the most relevant rewrite evidences for effectively answering an online query. We next propose a step-by-step LLM rewrite method that iteratively leverages the retrieved evidences to select and arrange rewrite rules with self-reflection. We conduct comprehensive experiments on real-world datasets and widely used benchmarks, and demonstrate the superior performance of our system, R-Bot, surpassing state-of-the-art query rewrite methods. The R-Bot system has been deployed at Huawei and with real customers, and the results show that the proposed R-Bot system achieves lower query latency.
title R-Bot: An LLM-based Query Rewrite System
topic Databases
Artificial Intelligence
Computation and Language
Machine Learning
url https://arxiv.org/abs/2412.01661