Making Databases Faster with LLM Evolutionary Sampling
Mehmet Hamza Erol, Xiangpeng Hao, Federico Bianchi, Ciro Greco, Jacopo Tagliabue, James Zou
TL;DR
This work tackles OLAP query performance by using LLMs to refine physical query plans at test time. It introduces DBPlanBench, a harness that exposes DataFusion's physical plans in a compact, patch-editable form and uses evolutionary sampling to guide semantic, correctness-preserving plan edits. The approach leverages semantic cardinality estimation and join-optimization strategies to yield substantial speedups (up to 4.78x) and demonstrates that optimizations discovered on small scales transfer to larger databases. A rigorous evaluation protocol with sandboxed executions and deterministic plan transfer substantiates the practicality and robustness of LLM-driven plan refinement for real-world database workloads.
Abstract
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 heuristics requires substantial engineering effort, and even when implemented, these heuristics often cannot take into account semantic correlations in queries and schemas that could enable better physical plans. Using our DBPlanBench harness for the DataFusion engine, we expose the physical plan through a compact serialized representation and let the LLM propose localized edits that can be applied and executed. We then apply an evolutionary search over these edits to refine candidates across iterations. Our key insight is that LLMs can leverage semantic knowledge to identify and apply non-obvious optimizations, such as join orderings that minimize intermediate cardinalities. We obtain up to 4.78$\times$ speedups on some queries and we demonstrate a small-to-large workflow in which optimizations found on small databases transfer effectively to larger databases.
