Handling SQL Nulls with Two-Valued Logic - Archive ouverte HAL Access content directly
Preprints, Working Papers, ... Year :

Handling SQL Nulls with Two-Valued Logic

(1, 2, 3, 4) , (1, 4)
1
2
3
4

Abstract

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.
Fichier principal
Vignette du fichier
2012.13198-2.pdf (327.06 Ko) Télécharger le fichier
Origin : Files produced by the author(s)

Dates and versions

hal-03104130 , version 1 (08-01-2021)

Identifiers

  • HAL Id : hal-03104130 , version 1

Cite

Leonid Libkin, Liat Peterfreund. Handling SQL Nulls with Two-Valued Logic. 2021. ⟨hal-03104130⟩
28 View
112 Download

Share

Gmail Facebook Twitter LinkedIn More