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 = NULLThe first query should obviously never return any results, but the same is true for the second one, because while
NULL IS NULL
yieldsTRUE
, always,NULL = NULL
evaluates toNULL
, which has the same effect asFALSE
according 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.