Zing Forum

Reading

Cost-Aware Optimization for Agent Query Execution: When Large Language Models Meet Database Query Optimization

This article introduces a new query execution paradigm called "Agent Query Execution" and its corresponding optimizer EnumGRPO. By interleaving planning and execution of Large Language Model (LLM)-based agents, this method achieves joint optimization of query cost and answer quality, resulting in a 317x cost reduction and an 18% accuracy improvement in the SWAN benchmark test.

查询优化大语言模型智能体强化学习数据库成本优化SWAN基准测试
Published 2026-06-02 12:52Recent activity 2026-06-03 14:18Estimated read 5 min
Cost-Aware Optimization for Agent Query Execution: When Large Language Models Meet Database Query Optimization
1

Section 01

Introduction: Key Points of Cost-Aware Optimization for Agent Query Execution

This article proposes a new paradigm called "Agent Query Execution" and its corresponding optimizer EnumGRPO. By interleaving planning and execution of Large Language Model (LLM)-based agents, it achieves joint optimization of query cost and answer quality. In the SWAN benchmark test, this method achieves a 317x cost reduction and an 18% accuracy improvement.

2

Section 02

Background: Limitations of Traditional Query Optimization and Challenges Brought by LLMs

Traditional database query optimization assumes that equivalent plans produce the same results, differing only in execution cost. However, after introducing LLM operators, their placement, order, and granularity simultaneously affect economic cost (token-based billing) and answer quality, and the optimal choice needs to be determined at runtime, making traditional cost models no longer applicable.

3

Section 03

Methodology: Agent Query Execution Paradigm and EnumGRPO Optimizer

Agent Query Execution Paradigm: Integrate LLMs into the query decision loop, where agents dynamically adjust the timing, type, and result combination of LLM calls. EnumGRPO Optimizer:

  • Learning phase: Enumerate multi-dimensional decisions (execution paradigm, operator type, placement, data range, projection width), collect quality-cost feedback to form heuristic rules;
  • Contextual reinforcement learning: Use historical feedback to guide decisions during inference, adapting to new query patterns without retraining.
4

Section 04

Evidence: Experimental Results from the SWAN Benchmark

In the SWAN benchmark, which includes 4 database scenarios:

  1. Cost reduction: The cost of LLM operators is reduced to $0.011 per query, a 317x decrease compared to the hybrid baseline;
  2. Accuracy improvement: A relative increase of 18%, reaching 35.4%;
  3. Generalization ability: Planning heuristics are transferable across the 4 databases.
5

Section 05

Conclusion and Applications: Technical Significance and Practical Scenario Value

Technical Insights: Flexibly represent traditional and LLM-enhanced operators, combine greedy heuristics with enumeration search, dynamically collect feedback, and support runtime adaptation. Application Prospects:

  • Enterprise scenarios: Provide economically feasible solutions for complex semantic queries;
  • Multimodal extension: Suitable for cost-quality trade-offs in image/audio and other data types;
  • Architectural impact: May reshape database systems by supporting agent planning as a core component.
6

Section 06

Limitations and Future Research Directions

Limitations: Contextual reinforcement learning is limited by window size, and performance on real-world workloads needs verification. Future Directions:

  • Explore efficient search algorithms to reduce learning overhead;
  • Integrate with existing learning-based optimizers;
  • Develop domain-specific strategies for healthcare, law, and other fields.