SQL查询其实很有限,多数可预测,未必需要大模型。
Are LLMs Overkill for Databases?: A Study on the Finiteness of SQL
- 分析376个数据库,发现自然语言转SQL的复杂度受限于实际需求。
- 70%的查询仅由13%的模板类型覆盖,呈幂律分布。
- 在数据库查询中,模板比大模型更安全、便宜且可审计。
得益于代码生成大模型,自然语言转SQL的数据检索变得更容易。但生成SQL究竟有多难?尽管数据库可能无限复杂,但查询的复杂性受现实用途和人类需求限制。通过对376个数据库的分析,我们发现自然语言问题对应的SQL查询在实际应用中是有限的。数据库表数量增加并不导致查询复杂度持续上升。在模板形式下,SQL查询频率呈现类似幂律的分布:仅13%的模板类型即可覆盖70%的测试查询,表明绝大多数查询具有高度可预测性。这提示,尽管大模型可用于代码生成,在数据库访问领域,其作用可能局限于一个狭窄而高度公式化的空间,使用预定义模板反而更安全、更经济且易于审计。
原文摘要 · Abstract (English)
Translating natural language to SQL for data retrieval has become more accessible thanks to code generation LLMs. But how hard is it to generate SQL code? While databases can become unbounded in complexity, the complexity of queries is bounded by real life utility and human needs. With a sample of 376 databases, we show that SQL queries, as translations of natural language questions are finite in practical complexity. There is no clear monotonic relationship between increases in database table count and increases in complexity of SQL queries. In their template forms, SQL queries follow a Power Law-like distribution of frequency where 70% of our tested queries can be covered with just 13% of all template types, indicating that the high majority of SQL queries are predictable. This suggests that while LLMs for code generation can be useful, in the domain of database access, they may be operating in a narrow, highly formulaic space where templates could be safer, cheaper, and auditable.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。