Enterprises commonly deploy heterogeneous database systems, each of which owns a distinct SQL dialect with different syntax rules, built-in functions, and execution constraints. However, most existing NL2SQL methods assume a single dialect (e.g., SQLite) and struggle to produce queries that are both semantically correct and executable on target engines. Prompt-based approaches tightly couple intent reasoning with dialect syntax, rule-based translators often degrade native operators into generic constructs, and multi-dialect fine-tuning suffers from cross-dialect interference. In this paper, we present Dial, a knowledge-grounded framework for dialect-specific NL2SQL. Dial introduces: (1) a Dialect-Aware Logical Query Planning module that converts natural language into a dialect-aware logical query plan via operator-level intent decomposition and divergence-aware specification; (2) HINT-KB, a hierarchical intent-aware knowledge base that organizes dialect knowledge into (i) a canonical syntax reference, (ii) a declarative function repository, and (iii) a procedural constraint repository; and (3) an execution-driven debugging and semantic verification loop that separates syntactic recovery from logic auditing to prevent semantic drift. We construct DS-NL2SQL, a benchmark covering six major database systems with 2,218 dialect-specific test cases. Experimental results show that Dial consistently improves translation accuracy by 10.25% and dialect feature coverage by 15.77% over state-of-the-art baselines. The code is at https://github.com/weAIDB/Dial.
翻译:企业通常部署异构数据库系统,每个系统都拥有独特的SQL方言,这些方言具有不同的语法规则、内置函数和执行约束。然而,大多数现有的自然语言转SQL方法都假设单一方言(例如SQLite),难以生成在目标引擎上既语义正确又可执行的查询。基于提示的方法将意图推理与方言语法紧密耦合,基于规则的翻译器通常将原生运算符降级为通用结构,而多方言微调则受到跨方言干扰的影响。本文提出Dial,一种用于方言特定自然语言转SQL的基于知识框架。Dial引入了:(1)方言感知逻辑查询规划模块,通过运算符级意图分解和差异感知规约,将自然语言转换为方言感知的逻辑查询计划;(2)HINT-KB,一个分层意图感知知识库,将方言知识组织为(i)规范语法参考,(ii)声明式函数库,以及(iii)过程式约束库;(3)执行驱动的调试与语义验证循环,将语法恢复与逻辑审计分离,以防止语义漂移。我们构建了DS-NL2SQL基准测试集,涵盖六个主要数据库系统,包含2,218个方言特定测试用例。实验结果表明,Dial相较于最先进的基线方法,翻译准确率持续提升10.25%,方言特性覆盖率提升15.77%。代码位于https://github.com/weAIDB/Dial。