arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2507.03384cs.DBcs.AI
收藏

LLM4Hint:利用大型语言模型进行离线查询优化中的提示推荐

LLM4Hint: Leveraging Large Language Models for Hint Recommendation in Offline Query Optimization

Key Laboratory of High Confidence Software Technologies, CS, Peking University, China(高性能软件技术重点实验室,计算机科学,北京大学,中国);ZTE Corporation(中兴通讯)

Suchen Liu, Jun Gao, Yinjun Han, Yang Lin

AI总结:

本文提出 LLM4Hint,利用中等规模 LLM 结合轻量级软提示、查询重写和显式匹配提示,为离线重复查询推荐优化提示,以低微调成本提升学习型查询优化器的有效性与泛化性。

摘要:

查询优化对于数据库管理系统(DBMS)中高效执行 SQL 查询至关重要,并且随着数据量的增长和硬件的进步,它始终具有吸引力。现有的传统优化器难以应对复杂工作负载所需的繁琐手工调优,而基于学习的方法在保证泛化性方面面临局限。随着大型语言模型(LLM)在各类下游任务中取得巨大成功,本文探索了如何将 LLM 融入以增强学习型优化器的泛化能力。尽管前景广阔,这种融合仍面临挑战,主要包括较高的模型推理延迟,以及由于 LLM 中的 token 序列与具有丰富数值特征的结构化 SQL 执行计划之间的固有差异所导致的巨大微调成本和次优性能。\n本文聚焦于离线优化中的重复查询以缓解高推理延迟问题,并提出 LLM4Hint,利用中等规模的主干 LLM 来推荐查询优化提示。LLM4Hint 通过以下方式实现目标:(i)集成一个轻量级模型来生成软提示,该提示捕获 DBMS 中的数据分布和 SQL 谓词,以提供充分的优化特征,同时减少输入到 LLM 的上下文长度;(ii)设计一种使用更大规模商用 LLM 的查询重写策略,以简化主干 LLM 的 SQL 语义并降低微调成本;(iii)引入显式匹配提示以促进 LLM 与轻量级模型之间的对齐,从而加速组合模型的收敛。实验表明,LLM4Hint 通过利用 LLM 更强的查询语句理解能力,在有效性和泛化性方面均优于最先进的学习型优化器。

英文摘要:

Query optimization is essential for efficient SQL query execution in DBMS, and remains attractive over time due to the growth of data volumes and advances in hardware. Existing traditional optimizers struggle with the cumbersome hand-tuning required for complex workloads, and the learning-based methods face limitations in ensuring generalization. With the great success of Large Language Model (LLM) across diverse downstream tasks, this paper explores how LLMs can be incorporated to enhance the generalization of learned optimizers. Though promising, such an incorporation still presents challenges, mainly including high model inference latency, and the substantial fine-tuning cost and suboptimal performance due to inherent discrepancy between the token sequences in LLM and structured SQL execution plans with rich numerical features. In this paper, we focus on recurring queries in offline optimization to alleviate the issue of high inference latency, and propose \textbf{LLM4Hint} that leverages moderate-sized backbone LLMs to recommend query optimization hints. LLM4Hint achieves the goals through: (i) integrating a lightweight model to produce a soft prompt, which captures the data distribution in DBMS and the SQL predicates to provide sufficient optimization features while simultaneously reducing the context length fed to the LLM, (ii) devising a query rewriting strategy using a larger commercial LLM, so as to simplify SQL semantics for the backbone LLM and reduce fine-tuning costs, and (iii) introducing an explicit matching prompt to facilitate alignment between the LLM and the lightweight model, which can accelerate convergence of the combined model. Experiments show that LLM4Hint, by leveraging the LLM's stronger capability to understand the query statement, can outperform the state-of-the-art learned optimizers in terms of both effectiveness and generalization.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑