用简化查询+大模型,自动翻译复杂SQL方言
RISE: Rule-Driven SQL Dialect Translation via Query Reduction
- 先删冗余元素生成简版查询,再让大模型翻译
- 在真实数据集上准确率达97.98%~100%
- 适合需要批量迁移数据库的应用开发者
跨关系型数据库管理系统的SQL方言转换对云迁移至关重要。传统工具依赖人工规则,维护成本高;虽有大模型辅助,但难以处理长而复杂的查询。本文提出RISE,一种基于大模型的方言转换方法:给定复杂源查询$Q_c$,先通过方言感知的查询简化技术去除无关元素,得到简化查询$Q_s$;再用大模型将$Q_s$翻译为$Q_{s^{'}}$,并自动提取方言$d$的转换规则$r_d$;最后用$r_d$作用于$Q_c$完成翻译,绕过原始复杂度。在TPC-DS和SQLProcBench两个真实基准上评估,RISE在TPC-DS上准确率达97.98%,在SQLProcBench上达100%,相比基线平均提升24.62%和238.41%。
原文摘要 · Abstract (English)
Translating SQL dialects across different relational database management systems (RDBMSs) is crucial for migrating RDBMS-based applications to the cloud. Traditional SQL dialect translation tools rely on manually-crafted rules, necessitating significant manual effort to support new RDBMSs and dialects. Although large language models (LLMs) can assist in translating SQL dialects, they often struggle with lengthy and complex SQL queries. In this paper, we propose RISE, a novel LLM-based SQL dialect translation approach that can accurately handle lengthy and complex SQL queries. Given a complex source query $Q_c$ that contains a SQL dialect $d$, we first employ a dialect-aware query reduction technique to derive a simplified query $Q_{s}$ by removing $d$-irrelevant SQL elements from $Q_c$. Subsequently, we utilize LLMs to translate $Q_{s}$ into $Q_{s^{'}}$, and automatically extract the translation rule $r_d$ for dialect $d$ based on the relationship between $Q_{s}$ and $Q_{s^{'}}$. By applying $r_d$ to $Q_c$, we can effectively translate the dialect $d$ within $Q_c$, thereby bypassing the complexity of the source query $Q_c$. We evaluate RISE on two real-world benchmarks, i.e., TPC-DS and SQLProcBench, comparing its performance against both the traditional rule-based tools and the LLM-based approaches with respect to translation accuracy. RISE achieves accuracies of 97.98% on TPC-DS and 100% on SQLProcBench, outperforming the baselines by an average improvement of 24.62% and 238.41%, respectively.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。