SQL is a widely adopted language for querying data, which has led to the development of various SQL analysis and rewriting tools. However, due to the diversity of SQL dialects, such tools often fail when encountering unrecognized dialect-specific syntax. While Large Language Models (LLMs) have shown promise in understanding SQL queries, their inherent limitations in handling hierarchical structures and hallucination risks limit their direct applicability in parsing. To address these limitations, we propose SQLFlex, a novel query rewriting framework that integrates grammar-based parsing with LLM-based segmentation to parse diverse SQL dialects robustly. Our core idea is to decompose hierarchical parsing to sequential segmentation tasks, which better aligns with the strength of LLMs and improves output reliability through validation checks. Specifically, SQLFlex uses clause-level segmentation and expression-level segmentation as two strategies that decompose elements on different levels of a query. We extensively evaluated SQLFlex on both real-world use cases and in a standalone evaluation. In SQL linting, SQLFlex outperforms SQLFluff in ANSI mode by 63.68% in F1 score while matching its dialect-specific mode performance. In test-case reduction, SQLFlex outperforms SQLess by up to 10 times in simplification rate. In the standalone evaluation, it parses 91.55% to 100% of queries across eight distinct dialects, outperforming all baseline parsers. We believe SQLFlex can serve as a foundation for many query analysis and rewriting use cases.


翻译:SQL是一种广泛用于数据查询的语言,这推动了各类SQL分析与重写工具的发展。然而,由于SQL方言的多样性,此类工具在遇到无法识别的方言特定语法时常常失效。尽管大语言模型在理解SQL查询方面展现出潜力,但其在处理层次结构方面的固有局限以及幻觉风险限制了它们在解析中的直接适用性。为应对这些局限,我们提出了SQLFlex,一种新颖的查询重写框架,它将基于语法的解析与基于大语言模型的分段相结合,以稳健地解析多种SQL方言。我们的核心思想是将层次化解析分解为序列化分段任务,这更好地契合了大语言模型的优势,并通过验证检查提高了输出可靠性。具体而言,SQLFlex采用子句级分段和表达式级分段两种策略,对查询的不同层级元素进行分解。我们在实际应用场景和独立评估中广泛测试了SQLFlex。在SQL代码检查任务中,SQLFlex在ANSI模式下以63.68%的F1分数超越SQLFluff,同时与其方言特定模式性能相当。在测试用例简化任务中,SQLFlex的简化率最高可达SQLess的10倍。在独立评估中,它在八种不同方言上实现了91.55%至100%的查询解析成功率,优于所有基线解析器。我们相信SQLFlex可为众多查询分析与重写应用场景提供基础支撑。

0
下载
关闭预览

相关内容

SQL 全名是结构化查询语言,是用于数据库中的标准数据查询语言,IBM 公司最早使用在其开发的数据库系统中。
面向统计学家的大型语言模型概述
专知会员服务
32+阅读 · 2025年3月16日
利用多个大型语言模型:关于LLM集成的调研
专知会员服务
35+阅读 · 2025年2月27日
大语言模型评估技术研究进展
专知会员服务
48+阅读 · 2024年7月9日
多语言大型语言模型:资源、分类和前沿综述
专知会员服务
53+阅读 · 2024年4月9日
金融领域自然语言处理研究资源大列表
专知
13+阅读 · 2020年2月27日
最全中文自然语言处理数据集、平台和工具整理
深度学习与NLP
34+阅读 · 2019年6月22日
【大数据】海量数据分析能力形成和大数据关键技术
产业智能官
17+阅读 · 2018年10月29日
从语言学到深度学习NLP,一文概述自然语言处理
人工智能学家
13+阅读 · 2018年1月28日
情感分析的新方法,使用word2vec对微博文本进行情感分析和分类
数据挖掘入门与实战
22+阅读 · 2018年1月6日
【大数据】数据挖掘与数据分析知识流程梳理
产业智能官
13+阅读 · 2017年9月22日
语料库构建——自然语言理解的基础
计算机研究与发展
11+阅读 · 2017年8月21日
国家自然科学基金
4+阅读 · 2015年12月31日
国家自然科学基金
3+阅读 · 2015年12月31日
国家自然科学基金
3+阅读 · 2015年12月31日
国家自然科学基金
8+阅读 · 2015年12月31日
国家自然科学基金
1+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
6+阅读 · 2014年12月31日
国家自然科学基金
25+阅读 · 2014年12月31日
国家自然科学基金
8+阅读 · 2014年12月31日
国家自然科学基金
4+阅读 · 2014年12月31日
A Survey of Large Language Models
Arxiv
500+阅读 · 2023年3月31日
VIP会员
最新内容
《面向海军应用的无人机网络安全仿真环境》
专知会员服务
5+阅读 · 4月7日
无人机与僵局:俄乌战争难以突破
专知会员服务
3+阅读 · 4月7日
《控制对手感知:电子战愿景与赋能技术》
专知会员服务
7+阅读 · 4月7日
自主、人工智能与可消耗集群时代的海军情报
专知会员服务
9+阅读 · 4月6日
“史诗狂怒行动”中的海军动态
专知会员服务
10+阅读 · 4月5日
相关VIP内容
面向统计学家的大型语言模型概述
专知会员服务
32+阅读 · 2025年3月16日
利用多个大型语言模型:关于LLM集成的调研
专知会员服务
35+阅读 · 2025年2月27日
大语言模型评估技术研究进展
专知会员服务
48+阅读 · 2024年7月9日
多语言大型语言模型:资源、分类和前沿综述
专知会员服务
53+阅读 · 2024年4月9日
相关资讯
金融领域自然语言处理研究资源大列表
专知
13+阅读 · 2020年2月27日
最全中文自然语言处理数据集、平台和工具整理
深度学习与NLP
34+阅读 · 2019年6月22日
【大数据】海量数据分析能力形成和大数据关键技术
产业智能官
17+阅读 · 2018年10月29日
从语言学到深度学习NLP,一文概述自然语言处理
人工智能学家
13+阅读 · 2018年1月28日
情感分析的新方法,使用word2vec对微博文本进行情感分析和分类
数据挖掘入门与实战
22+阅读 · 2018年1月6日
【大数据】数据挖掘与数据分析知识流程梳理
产业智能官
13+阅读 · 2017年9月22日
语料库构建——自然语言理解的基础
计算机研究与发展
11+阅读 · 2017年8月21日
相关基金
国家自然科学基金
4+阅读 · 2015年12月31日
国家自然科学基金
3+阅读 · 2015年12月31日
国家自然科学基金
3+阅读 · 2015年12月31日
国家自然科学基金
8+阅读 · 2015年12月31日
国家自然科学基金
1+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
6+阅读 · 2014年12月31日
国家自然科学基金
25+阅读 · 2014年12月31日
国家自然科学基金
8+阅读 · 2014年12月31日
国家自然科学基金
4+阅读 · 2014年12月31日
Top
微信扫码咨询专知VIP会员