arXiv:2604.07041cs.DBcs.AI2026-04被引 1

用智能代理分步生成复杂SQL,解决大数据库查询难题。

AV-SQL: Decomposing Complex Text-to-SQL Queries with Agentic Views

  • 将复杂查询拆解为多个智能代理协作处理
  • 在Spider 2.0上达到70.38%执行准确率,超越现有方法
  • 适合需要跨多表推理的复杂数据库查询场景

Text-to-SQL任务旨在将自然语言查询转化为可执行的SQL语句,使非专业用户无需手动编写SQL即可访问结构化数据。尽管大型语言模型(LLMs)推动了该领域快速发展,现有方法在真实场景中仍面临挑战:数据库模式庞大,查询需多步推理且涉及多个关联表。此时,提供完整模式常超出上下文窗口限制,而单次生成易因语法错误或模式链接错误导致生成不可执行的SQL。为此,我们提出AV-SQL框架,通过一系列专用LLM代理将复杂Text-to-SQL分解为可管理的步骤。核心是“代理视图”概念:由代理生成的Common Table Expressions(CTEs),用于封装中间查询逻辑并从大模式中筛选相关元素。AV-SQL包含三个阶段:(1) 重写代理压缩并澄清输入查询;(2) 视图生成代理处理模式片段生成代理视图;(3) 计划、生成与修订代理协同将这些视图组合成最终SQL。大量实验表明,AV-SQL在具有挑战性的Spider 2.0基准上实现70.38%的执行准确率,优于现有最佳方法;在标准数据集上也表现良好:Spider为85.59%,BIRD为72.16%,KaggleDBQA为63.78%。源代码已公开于https://github.com/pminhtam/AV-SQL。

原文摘要 · Abstract (English)

Text-to-SQL is the task of translating natural language queries into executable SQL for a given database, enabling non-expert users to access structured data without writing SQL manually. Despite rapid advances driven by large language models (LLMs), existing approaches still struggle with complex queries in real-world settings, where database schemas are large and questions require multi-step reasoning over many interrelated tables. In such cases, providing the full schema often exceeds the context window, while one-shot generation frequently produces non-executable SQL due to syntax errors and incorrect schema linking. To address these challenges, we introduce AV-SQL, a framework that decomposes complex Text-to-SQL into a pipeline of specialized LLM agents. Central to AV-SQL is the concept of agentic views: agent-generated Common Table Expressions (CTEs) that encapsulate intermediate query logic and filter relevant schema elements from large schemas. AV-SQL operates in three stages: (1) a rewriter agent compresses and clarifies the input query; (2) a view generator agent processes schema chunks to produce agentic views; and (3) a planner, generator, and revisor agent collaboratively compose these views into the final SQL query. Extensive experiments show that AV-SQL achieves 70.38% execution accuracy on the challenging Spider 2.0 benchmark, outperforming state-of-the-art baselines, while remaining competitive on standard datasets with 85.59% on Spider, 72.16% on BIRD and 63.78% on KaggleDBQA. Our source code is available at https://github.com/pminhtam/AV-SQL.

Text-to-SQL智能代理复杂查询大模型

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