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.
Abstract (translated)
翻译:查询重写是一种通过修改 SQL 查询的结构而不改变查询结果来生成更有效的查询的方法,一直是一个重要的研究问题。为了在重写过程中保持等价关系,传统的查询重写方法总是根据某些重写规则重写查询。然而,一些问题仍然存在。首先,现有的寻找最优选择或重写规则的方法仍然有限,并且重写过程始终需要大量的资源。涉及发现新重写规则的方法通常需要复杂的证明结构逻辑或广泛的用户交互。其次,当前的查询重写方法通常高度依赖于数据库管理系统成本估算器,这些估算器通常不准确。在本文中,我们通过提出一种名为 LLM-R2 的查询重写新方法来解决这些问题。我们使用一个大型语言模型(LLM)来提出数据库重写系统可能的重写规则。为了进一步提高 LLM 在推荐重写规则方面的推理能力,我们通过课程学习曲线训练对比模型,学习查询表示,并为 LLM 选择有效的查询演示。实验结果表明,我们的方法可以显著提高查询执行效率,并优于基线方法。此外,我们的方法在不同数据集上的鲁棒性很高。
URL
https://arxiv.org/abs/2404.12872