研究数据库规范化对自然语言转SQL的影响,发现不同查询类型需匹配不同设计。
Exploring Database Normalization Effects on SQL Generation
- 对比1NF到3NF的规范设计与去规范化设计在生成SQL时的表现差异。
- 简单查询中去规范化更准确,聚合查询中规范化表现更优。
- 提供少量示例可显著改善规范化带来的表选择和连接错误。
模式设计,尤其是规范化,是自然语言转SQL(NL2SQL)系统中的关键但常被忽视的因素。以往研究多在固定模式上评估模型,忽略了设计本身对性能的影响。我们首次系统性地研究了模式规范化的影响,评估了八种领先的大语言模型在具有不同规范化程度的合成数据集和真实学术论文数据集上的表现。我们构建了符合形式化规范化标准(1NF–3NF)的受控合成数据集,以及包含实际设计模式的真实学术数据集。结果表明,去规范化模式在简单检索查询中表现出高准确性,即使在零样本设置下使用低成本模型也表现良好;而规范化模式(2NF/3NF)则带来基表选择和连接类型预测错误等问题,但通过提供少量示例可显著缓解。对于聚合查询,规范化模式表现更好,主要因其对数据重复和空值问题更具鲁棒性,而这些问题是去规范化模式中错误的主要来源。研究结论表明,NL2SQL应用的最佳模式设计取决于目标查询类型。本研究强调在开发NL2SQL接口时应考虑模式设计,并推动在真实场景中引入自适应模式选择。
原文摘要 · Abstract (English)
Schema design, particularly normalization, is a critical yet often overlooked factor in natural language to SQL (NL2SQL) systems. Most prior research evaluates models on fixed schemas, overlooking the influence of design on performance. We present the first systematic study of schema normalization's impact, evaluating eight leading large language models on synthetic and real-world datasets with varied normalization levels. We construct controlled synthetic datasets with formal normalization (1NF-3NF) and real academic paper datasets with practical schemes. Our results show that denormalized schemas offer high accuracy on simple retrieval queries, even with cost-effective models in zero-shot settings. In contrast, normalized schemas (2NF/3NF) introduce challenges such as errors in base table selection and join type prediction; however, these issues are substantially mitigated by providing few-shot examples. For aggregation queries, normalized schemas yielded better performance, mainly due to their robustness against the data duplication and NULL value issues that cause errors in denormalized schemas. These findings suggest that the optimal schema design for NL2SQL applications depends on the types of queries to be supported. Our study demonstrates the importance of considering schema design when developing NL2SQL interfaces and integrating adaptive schema selection for real-world scenarios.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。