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的设计基于一种三价逻辑(3VL),而不是熟悉的布林逻辑,其真实和假的真理价值是真实和假的,以适应处理空格时未知的额外真相价值。它被视为SQL表达式的不可或缺,但同时也因导致不直观的询问行为而遭到大量批评,从而成为程序错误的来源。我们表明,与广泛持有的观点相反,SQL本本可以基于标准布林逻辑来设计,而不会丧失任何表达性,也不会放弃无效。SQL的这一方法本身遵循了SQL的评估,它只保留了用于处理空格时处理空格的附加真理价值。我们显示,由于空格导致未知的混搭,导致同样直观的查询方式SQLL,而没有使用第三个真理值。在两种价值的语义下写的各种文字只能有效地翻译成标准SQL,因此可以执行任何现有的RDBMS。这些结果是SQL核心的, 包括SLEK-F-FR QL 可能不是直观的逻辑-RULL 和RULLLLL 的更深入的解算法。我们的系统/CRULLLLLLL 需要显示许多新的逻辑/RUIULLL 。这些新的条件,这些逻辑/RULLLLLLLLLLLLLLL 。这些逻辑/RL 。这些逻辑/RUL 和RULRUL 。这些逻辑/RULLLLLRULLL 。它们可以有力地显示许多次的更新的结果,它们显示的是,它们显示很多子 。