This optimisation is really silly, but hey, why not. If users write impossible predicates, then why even execute them? Here are some examples:-- "Obvious" SELECT * FROM actor WHERE 1 = 0 -- "Subtle" SELECT * FROM actor WHERE NULL = NULL
The first query should obviously never return any results, but the same is true for the second one, because while
NULL IS NULLyields
NULL = NULLevaluates to
NULL, which has the same effect as
FALSEaccording to three-valued logic.
This doesn’t need much explanation, so let’s immediately jump to see which databases optimise this:
I was a bit surprised at how well DB2 did in this set.