The design of SQL is based on a three-valued logic (3VL), rather than the familiar Boolean logic. 3VL adds a truth value unknown to true and false to handle nulls. Viewed as indispensable for SQL expressiveness, it is at the same time much criticized for unintuitive behavior of queries and 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 WHERE evaluate to true. We show that conflating unknown 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: SELECT-FROM-WHERE-GROUP BY-HAVING queries extended with subqueries and IN/EXISTS/ANY/ALL conditions, and recursive queries. We also investigate new optimization rules enabled by the two-valued SQL, and show that for many queries, including most of those found in benchmarks such as TPC-H and TPC-DS, there is no difference between three- and two-valued versions.
翻译:SQL的设计基于三种价值的逻辑(3VL),而不是熟悉的布尔兰逻辑。 3VL增加了一个真实和虚假的真理价值,以处理空壳。 3VL认为,对于SQL的表达性来说,这是不可或缺的,但同时,它也因不直观的询问行为而受到很大批评,并且是程序错误的来源。 我们表明,与广泛持有的观点相反,SQL本来可以基于标准的布尔兰逻辑来设计,而不会失去任何表达性,也不会放弃无效。 方法本身遵循SQL的评估,它只保留真实和虚假的假的图例。 我们显示,未知的混杂和假的SQL的表达性版本没有使用第三个真相价值。 与广泛持有的两种价值的语义下写的可以有效地翻译成标准SQL, 从而在任何现有的数据库上执行。 这些结果覆盖了SQL标准的核心:SELE-FROM-WhER-GROUP, 它只保留真实到真实的条件。 我们展示了SQL的同样清晰的版本, 和S-RA-RAVL的三版, 通过我们发现/RAST-RL 和S- Rest- Rest- Rest 之间的 和S- Rest- Rest- Rest- 之间的 和S- tris