arXiv:2602.10387cs.DBcs.AI2026-02

用大模型优化数据库查询计划,提升执行效率。

Test-Time Optimization of Physical Query Plans with LLMs

  • 大模型分析查询语义,提出局部优化建议。
  • 在TPC-H上实现最高4.78倍加速,平均提速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倍。同时验证小规模优化可有效迁移至大规模,支持低成本从小到大的优化工作流。

原文摘要 · Abstract (English)

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.

数据库大模型查询优化测试时优化

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