当前位置: X-MOL 学术arXiv.cs.DB › 论文详情
Our official English website, www.x-mol.net, welcomes your feedback! (Note: you will need to create a separate account there.)
Handling SQL Nulls with Two-Valued Logic
arXiv - CS - Databases Pub Date : 2020-12-24 , DOI: arxiv-2012.13198
Leonid Libkin, Liat Peterfreund

The design of SQL is based on a three-valued logic (3VL), rather than the familiar Boolean logic with truth values true and false, to accommodate the additional truth value unknown for handling nulls. It is viewed as indispensable for SQL expressiveness but is at the same time much criticized for leading to unintuitive behavior of queries and thus being a source of programmer mistakes. We show that, contrary to the widely held view, SQL could have been designed based on the standard Boolean logic, without any loss of expressiveness and without giving up nulls. The approach itself follows SQL's evaluation which only retains tuples for which conditions in the WHERE clause evaluate to true. We show that conflating unknown, resulting from nulls, with false leads to an equally expressive version of SQL that does not use the third truth value. Queries written under the two-valued semantics can be efficiently translated into the standard SQL and thus executed on any existing RDBMS. These results cover the core of the SQL 1999 Standard, including SELECT-FROM-WHERE-GROUP BY-HAVING queries extended with subqueries and IN/EXISTS/ANY/ALL conditions, and recursive queries. We provide two extensions of this result showing that no other way of converting 3VL into Boolean logic, nor any other many-valued logic for treating nulls could have possibly led to a more expressive language. These results not only present small modifications of SQL that eliminate the source of many programmer errors without the need to reimplement database internals, but they also strongly suggest that new query languages for various data models do not have to follow the much criticized SQL's three-valued approach.

中文翻译:

使用二值逻辑处理SQL空值

SQL的设计基于三值逻辑(3VL),而不是熟悉的具有真值true和false的布尔逻辑,以容纳用于处理null的未知的其他真值。它被认为对于SQL表达来说是必不可少的,但同时又因导致查询的不直观行为而备受批评,从而成为程序员错误的根源。我们证明,与普遍持有的观点相反,SQL可以基于标准布尔逻辑进行设计,而不会损失任何可表达性并且不会放弃空值。该方法本身遵循SQL的评估,该评估仅保留WHERE子句中条件评估为true的元组。我们表明,将由null导致的unknown与false混合会导致不使用第三个真值的同等表达形式的SQL。使用二值语义编写的查询可以有效地转换为标准SQL,从而可以在任何现有RDBMS上执行。这些结果涵盖了SQL 1999 Standard的核心,包括使用子查询和IN / EXISTS / ANY / ALL条件扩展的SELECT-FROM-WHERE-GROUP BY-HAVING查询以及递归查询。我们提供了此结果的两个扩展,表明没有其他方法可以将3VL转换为布尔逻辑,也没有其他任何用于处理null的多值逻辑可能导致更富表现力的语言。这些结果不仅表示对SQL的微小修改,从而消除了许多程序员错误的根源,而无需重新实现数据库内部结构,而且还强烈暗示,针对各种数据模型的新查询语言不必遵循备受批评的SQL的三值式方法。
更新日期:2020-12-25
down
wechat
bug