Sunday, September 5, 2010

NULLs and the Database

Oracle is not a relational database:

You'll see here that Codd is actually agreeing with nulls - which annoyed Date and they had a whole series of articles on what nulls mean and why it's a mistake - in the late 80s, early 90s. Basically
Date seemed to win the debate - at least in my mind.

Date was saying that nulls lead to 3 values logic (3VL) which leads to errors in logic things like NULL AND T in truth tables for examples - nulls make no logical sense - and as a system based on relations and logic it's a bad system.

Trivalent Logic:

Hibernate UserType
There's a reasonable example:

This one lets nulls but combines readResolve().

Thoughts on the counter arguments??:
Nulls aren't evil. They aren't logical - they're simply a mistake.
A good article about a different domain (Geo science) and how missing data, nulls and the problems that there are:

Calculations with NULL
Basically you can't compute on null - hence NPE.

Another example is that COUNT counts nulls but other aggregates don't (AVG and SUM). If nulls were values why can't you average them or sum them? Why can you count them?

Relational databases are based on relations and set theory. Sets are empty - they aren't null. And semantics with a good foundation in maths makes the whole thing just generally better (another book "Third Manifesto" goes into some detail about what a proper relational database would look like).

Another Date book really describes what an outerjoin (again nulls cause problems there) is and so on:

The guy that introduced NULLs into SQL and RDBMSs (Codd), said later that one null was inadequate and SQL should be enhanced to allow for two nulls: 1 for unset (Missing but Applicable), 1 for missing (Missing but Inapplicable)