arXiv:2504.00882cs.DBcs.AI2025-04被引 4

用大模型+规则混合方案,自动翻译复杂SQL语句

CrackSQL: A Hybrid SQL Dialect Translation System Powered by Large Language Models

  • 结合规则与大模型,分功能拆解复杂SQL
  • 支持三种模式,准确率显著优于纯大模型方法
  • 适合数据库迁移、跨平台查询的开发者使用

方言转换在异构数据库系统间实现无缝交互中起关键作用。然而,由于语法差异和细微语义变化,将SQL查询从一种方言(如PostgreSQL)转换为另一种(如MySQL)仍具挑战性。现有方法包括手动重写、基于规则的系统以及基于大语言模型(LLM)的技术,往往需要高维护成本(如定制转换规则)或产生不可靠结果(如LLM生成不存在的函数),尤其在处理复杂查询时更为明显。在本次演示中,我们提出CrackSQL,首个融合规则与大模型的混合式SQL方言转换系统,以克服上述局限。CrackSQL利用大模型的适应性减少人工干预,同时通过基于功能的查询处理对长而复杂的SQL进行分段,提升翻译准确性。为进一步增强鲁棒性,引入新颖的跨方言语法嵌入模型实现精确语法对齐,并采用自适应的局部到全局转换策略有效解决查询操作间的依赖关系。CrackSQL支持三种转换模式,提供包括网页控制台、PyPI包和命令行提示在内的多种部署与访问方式,便于在各类实际场景中应用。

原文摘要 · Abstract (English)

Dialect translation plays a key role in enabling seamless interaction across heterogeneous database systems. However, translating SQL queries between different dialects (e.g., from PostgreSQL to MySQL) remains a challenging task due to syntactic discrepancies and subtle semantic variations. Existing approaches including manual rewriting, rule-based systems, and large language model (LLM)-based techniques often involve high maintenance effort (e.g., crafting custom translation rules) or produce unreliable results (e.g., LLM generates non-existent functions), especially when handling complex queries. In this demonstration, we present CrackSQL, the first hybrid SQL dialect translation system that combines rule and LLM-based methods to overcome these limitations. CrackSQL leverages the adaptability of LLMs to minimize manual intervention, while enhancing translation accuracy by segmenting lengthy complex SQL via functionality-based query processing. To further improve robustness, it incorporates a novel cross-dialect syntax embedding model for precise syntax alignment, as well as an adaptive local-to-global translation strategy that effectively resolves interdependent query operations. CrackSQL supports three translation modes and offers multiple deployment and access options including a web console interface, a PyPI package, and a command-line prompt, facilitating adoption across a variety of real-world use cases

SQL转换大模型数据库

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