arXivDaily arXiv每日学术速递 周一至周五更新
感恩节,周五至周末无更新,大家顺遂。周一再来吧
arXiv 2602.10387cs.DBcs.AI
收藏

基于LLM的物理查询计划测试时优化

Test-Time Optimization of Physical Query Plans with LLMs

Stanford University(斯坦福大学);University of Wisconsin-Madison(威斯康星大学麦迪逊分校);TogetherAI;Bauplan

Mehmet Hamza Erol, Xiangpeng Hao, Federico Bianchi, Ciro Greco, Jacopo Tagliabue, James Zou

AI总结:

提出DBPlanBench框架,利用LLM在测试时通过语义推理和进化搜索优化物理查询计划,在OLAP查询中实现1.05-1.12倍中位数加速,并支持小规模到大规模的迁移。

摘要:

传统查询优化依赖于基于成本的优化器,使用预定义的启发式和统计模型来估计执行成本(如运行时间、内存和I/O)。改进这些需要大量的工程努力,但它们通常无法利用查询和模式中的语义相关性来获得更好的物理计划。然而,大型语言模型(LLMs)能够推理列语义、值分布以及经典统计所忽略的更广泛的领域上下文。我们介绍了DBPlanBench,一个用于DataFusion引擎的框架,它通过紧凑的序列化表示暴露物理计划,并将LLM提出的编辑作为JSON补丁应用。在此框架上,我们实例化了一个测试时优化工作流,其中LLM检查物理查询计划,基于语义推理提出局部编辑,并通过进化搜索在迭代中优化候选方案。我们针对OLAP查询,其中重复执行的重负载使得即使是微小的效率提升也能转化为显著的累积节省。我们特别将评估重点放在连接重排序和连接侧选择上,其中基数估计误差会复合倍增。在TPC-H上中位数加速达到1.10-1.12倍,在TPC-DS上达到1.05-1.07倍,某些查询加速高达4.78倍。我们还证明了在小规模因子下发现的优化可以有效地迁移到更大规模,支持低成本的小规模到大工作流。

英文摘要:

Traditional query optimization relies on cost-based optimizers that estimate execution cost (e.g., runtime, memory, and I/O) using predefined heuristics and statistical models. Improving these requires substantial engineering effort, yet they often cannot exploit semantic correlations in queries and schemas that could enable better physical plans. Large language models (LLMs), however, can reason about column semantics, value distributions, and broader domain context that classical statistics miss. We introduce DBPlanBench, a harness for the DataFusion engine that exposes physical plans through a compact serialized representation and applies LLM-proposed edits as JSON patches. On this harness, we instantiate a test-time optimization workflow where an LLM examines physical query plans, proposes localized edits based on semantic reasoning, and an evolutionary search refines the candidates across iterations. We target OLAP queries, where heavy, repeated execution turns even small efficiency gains into substantial cumulative savings. We specifically focus our evaluation on join reordering and join-side selection, where cardinality-estimation errors compound multiplicatively. Median speedups reach $1.10$-$1.12\times$ on TPC-H and $1.05$-$1.07\times$ on TPC-DS, with some achieving up to $4.78\times$. We also demonstrate that optimizations discovered at small scale factors transfer effectively to larger ones, supporting a low-cost small-to-large workflow.

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

↑