arXiv:2505.18122cs.CL2025-05被引 1

通过简化数据库模式提升多表SQL生成准确率

UNJOIN: Enhancing Multi-Table Text-to-SQL Generation via Schema Simplification

  • 将所有表的列名合并为单表表示,先专注找对表和列
  • 在简化模式上生成SQL后,再还原为原始结构的JOIN/UNION
  • 无需数据或微调,适配不同数据库且性能领先

大语言模型在单表Text-to-SQL任务中表现优异,但在多表数据库中仍面临模式复杂、关联操作困难等问题。现有方法常因表列检索不准、JOIN/UNION生成错误而失效,且难以跨模式泛化。为此,我们提出UNJOIN,一种两阶段框架:第一阶段将数据库所有表的列名合并为单表表示,通过前缀标注表名,使模型专注精准检索;第二阶段在此简化模式上生成SQL,并映射回原模式,重构连接逻辑。在SPIDER和BIRD数据集上的评估表明,UNJOIN达到或超过当前最优基线。该方法仅依赖模式信息,无需数据访问或微调,具备良好的可扩展性和跨库适应性。

原文摘要 · Abstract (English)

Recent advances in large language models (LLMs) have greatly improved Text-to-SQL performance for single-table queries. But, it remains challenging in multi-table databases due to complex schema and relational operations. Existing methods often struggle with retrieving the right tables and columns, generating accurate JOINs and UNIONs, and generalizing across diverse schemas. To address these issues, we introduce UNJOIN, a two-stage framework that decouples the retrieval of schema elements from SQL logic generation. In the first stage, we merge the column names of all tables in the database into a single-table representation by prefixing each column with its table name. This allows the model to focus purely on accurate retrieval without being distracted by the need to write complex SQL logic. In the second stage, the SQL query is generated on this simplified schema and mapped back to the original schema by reconstructing JOINs, UNIONs, and relational logic. Evaluations on SPIDER and BIRD datasets show that UNJOIN matches or exceeds the state-of-the-art baselines. UNJOIN uses only schema information, which does not require data access or fine-tuning, making it scalable and adaptable across databases.

Text-to-SQL多表查询模式简化LLM应用

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