集成递归查询语言(完整版本)
Language-Integrated Recursive Queries (Full Version)
AI总结:
本文提出TyQL,通过类型级模式匹配和命名元组实现安全递归查询,解决SQL递归安全性和正确性问题,提升查询性能。
摘要:
性能关键的工业应用,包括大规模程序、网络和分布式系统分析,依赖固定点计算。SQL:1999引入递归公共表表达式(CTEs)扩展了关系数据库系统处理固定点计算的能力,通过将计算靠近数据带来显著性能优势。然而,递归使SQL成为图灵完备的编程语言,带来不可恢复的安全性和正确性风险。SQL本身缺乏固定语义,因其规范用自然语言编写,充满歧义,数据库供应商以不同方式解决。因此,必须依赖查询的孤立数学属性来推断正确性,而非从语义不一致的语言中获得统一形式模型。为解决这些挑战,我们提出一种校验,自动从嵌入递归查询中推导数学属性,并根据数据库后端拒绝可能导致三种递归查询错误的查询——数据库错误、错误结果和非终止。我们引入TyQL,一种在Scala中实现的实用实现,用于安全、递归语言集成查询。通过命名元组和类型级模式匹配,TyQL确保查询的可移植性和安全性,显示与原始SQL字符串相比无性能损失,同时在非递归SQL查询上实现三量级的速度提升。
英文摘要:
Performance-critical industrial applications, including large-scale program, network, and distributed system analyses, rely on fixed-point computations. The introduction of recursive common table expressions (CTEs) using the WITH RECURSIVE keyword in SQL:1999 extended the ability of relational database systems to handle fixed-point computations, unlocking significant performance advantages by allowing computation to move closer to the data. Yet with recursion, SQL becomes a Turing-complete programming language and, with that, unrecoverable safety and correctness risks. SQL itself lacks a fixed semantics, as the SQL specification is written in natural language, full of ambiguities that database vendors resolve in divergent ways. As a result, reasoning about the correctness of recursive SQL programs must rely on isolated mathematical properties of queries rather than wrestling a unified formal model out of a language with notoriously inconsistent semantics. To address these challenges, we propose a calculus that automatically derives mathematical properties from embedded recursive queries and, depending on the database backend, rejects queries that may lead to the three classes of recursive query errors - database errors, incorrect results, and non-termination. We introduce TyQL, a practical implementation in Scala for safe, recursive language-integrated query. Using Named-Tuples and type-level pattern matching, TyQL ensures query portability and safety, showing no performance penalty compared to raw SQL strings while unlocking a three-orders-of-magnitude speedup over non-recursive SQL queries.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。