arXivDaily arXiv每日学术速递 周一至周五更新
arXiv周末暂无论文更新,休息一下吧,周末愉快~~
arXiv 2502.05562cs.DB
收藏

大型语言模型能否充当关系数据库的查询优化器?

Can Large Language Models Be Query Optimizer for Relational Databases?

Jie Tan, Kangfei Zhao, Rui Li, Jeffrey Xu Yu, Chengzhi Piao, Hong Cheng, Helen Meng, Deli Zhao, Yu Rong

AI总结:

本文提出基于PostgreSQL的LLM查询优化器LLM-QO,通过QInstruct数据配方和两阶段微调直接生成执行计划,在三个工作负载上优于传统与学习型优化器。

摘要:

查询优化旨在为给定查询寻找优化后的执行计划,是数据库管理系统(DBMS)中在指数级增长的计划空间内进行复杂规划与决策的问题。传统优化器严重依赖由各种启发式规则和经验调优构建的特定代价模型,可能导致生成次优计划。近年来,大型语言模型(LLMs)的发展已展现出其在解决复杂规划与决策问题(如算术和程序化任务)方面的潜力。本文尝试探索LLMs在处理查询优化中的潜力,并提出一个基于LLM的初步查询优化器,命名为LLM-QO,其构建于PostgreSQL的执行引擎之上。在LLM-QO中,我们以自回归方式形式化查询优化,直接生成执行计划而无需显式枚举计划。为研究LLM-QO所需的关键输入,我们设计了一种名为QInstruct的定制数据配方,用于从各种优化器收集训练数据,并将数据库元数据、查询及对应计划序列化为文本格式。基于QInstruct,我们实现了一个两阶段微调流程,即查询指令调优(QIT)和查询直接偏好优化(QDPO),以增强通用LLMs处理查询优化的能力。在我们的实验中,LLM-QO能够生成有效且高质量的计划,并在三个查询工作负载上一致地优于传统优化器和基于学习的优化器。我们的发现验证了LLMs可以被构建为查询优化器,其中泛化性、效率和适应性值得进一步研究。

英文摘要:

Query optimization, which finds the optimized execution plan for a given query, is a complex planning and decision-making problem within the exponentially growing plan space in database management systems (DBMS). Traditional optimizers heavily rely on a certain cost model constructed by various heuristics and empirical tuning, probably leading to generating suboptimal plans. Recent developments of Large Language Models (LLMs) have demonstrated their potential in solving complex planning and decision-making problems, such as arithmetic and programmatic tasks. In this paper, we try to explore the potential of LLMs in handling query optimization and propose a tentative LLM-based query optimizer dubbed LLM-QO, established on PostgreSQL's execution engine. In LLM-QO, we formulate query optimization in an autoregressive fashion which directly generates the execution plan without explicit plan enumeration. To investigate the essential input of LLM-QO, we design a customized data recipe named QInstruct to collect the training data from various optimizers and serialize the database's meta data, queries and corresponding plans into a textual format. Based on QInstruct, we implement a two-stage fine-tuning pipeline, Query Instruction Tuning (QIT) and Query Direct Preference Optimization (QDPO), to empower the capability of general-purpose LLMs in handling query optimization. In our experiments, LLM-QO can generate valid and high-quality plans and consistently outperforms both traditional and learned optimizers on three query workloads. Our findings verify that LLMs can be derived as query optimizers where generalization, efficiency and adaptivity deserve further research efforts.

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

↑