LLM-R2:一种大型语言模型增强的基于规则的重写系统,用于提高查询效率。
LLM-R2: A Large Language Model Enhanced Rule-based Rewrite System for Boosting Query Efficiency
April 19, 2024
作者: Zhaodonghui Li, Haitao Yuan, Huiming Wang, Gao Cong, Lidong Bing
cs.AI
摘要
查询重写旨在通过改变SQL查询的结构而不改变查询结果来生成更有效的查询,这一直是一个重要的研究问题。为了在重写过程中保持重写后的查询与原始查询的等价性,传统的查询重写方法总是遵循特定的重写规则来重写查询。然而,仍然存在一些问题。首先,现有的寻找最佳重写规则选择或顺序的方法仍然有限,而且这一过程通常耗费大量资源。涉及发现新重写规则的方法通常需要复杂的结构逻辑证明或大量用户交互。其次,当前的查询重写方法通常高度依赖于数据库管理系统的成本估算器,这些估算器通常不准确。在本文中,我们通过提出一种名为LLM-R2的查询重写新方法来解决这些问题,采用大型语言模型(LLM)为数据库重写系统提出可能的重写规则。为了进一步提高LLM在推荐重写规则方面的推理能力,我们通过课程训练对比模型来学习查询表示,并为LLM选择有效的查询演示。实验结果表明,我们的方法可以显著提高查询执行效率,并胜过基准方法。此外,我们的方法在不同数据集上表现出高鲁棒性。
English
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.Summary
AI-Generated Summary