arXiv:2507.03384cs.DBcs.AI2025-07

用大模型推荐查询优化提示,提升数据库性能和泛化能力。

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

  • 用轻量模型生成软提示,降低大模型输入长度
  • 通过重写SQL简化语义,减少微调成本
  • 引入显式匹配提示,加速模型收敛,适合数据库优化研究者

查询优化对高效执行SQL至关重要,但传统优化器在复杂工作负载下需繁琐调参,学习方法则存在泛化不足问题。本文提出LLM4Hint,利用中等规模大模型为离线查询优化推荐提示。通过三个关键设计:(i) 轻量模型生成软提示,融合数据分布与SQL谓词信息,缩短上下文长度;(ii) 采用大型商用大模型重写SQL,简化语义以降低微调成本;(iii) 引入显式匹配提示,促进大模型与轻量模型对齐,加速联合模型收敛。实验表明,LLM4Hint凭借大模型对查询语义的理解能力,在有效性和泛化性上均优于当前最先进学习型优化器。

原文摘要 · Abstract (English)

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.

数据库大模型优化提示工程

Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。