Language-integrated query based on comprehension syntax is a powerful technique for safe database programming, and provides a basis for advanced techniques such as query shredding or query flattening that allow efficient programming with complex nested collections. However, the foundations of these techniques are lacking: although SQL, the most widely-used database query language, supports heterogeneous queries that mix set and multiset semantics, these important capabilities are not supported by known correctness results or implementations that assume homogeneous collections. In this paper we study language-integrated query for a heterogeneous query language $NRC_\lambda(Set,Bag)$ that combines set and multiset constructs. We show how to normalize and translate queries to SQL, and develop a novel approach to querying heterogeneous nested collections, based on the insight that ``local'' query subexpressions that calculate nested subcollections can be ``lifted'' to the top level analogously to lambda-lifting for local function definitions.
翻译:基于理解语法的语言整合查询是安全数据库编程的有力技术,为查询碎条或查询平化等先进技术提供了基础,从而能够以复杂的嵌套收藏有效编程。然而,这些技术的基础仍然缺乏:虽然最广泛使用的数据库查询语言SQL支持混合组合和多设置语义的多样化查询,但这些重要能力没有已知的正确性结果或假定同质收藏的实施的支持。在本文中,我们研究混合查询语言 $NRC ⁇ lambda(Set,Bag) 的语言整合查询,该语言将集成和多设置构造结合起来。我们展示了如何将查询标准化和翻译到 SQL,并根据“本地查询”可计算嵌套子收藏的子表达式可以“提升”到顶级,类似于用于本地函数定义的 lamda 提升。