OiO.lk Blog SQL Is this SQL clause meaningless?
SQL

Is this SQL clause meaningless?


I ran across something strange in the SQLite "SqlLogicTest" test suite:

WHERE (e>c OR e<d)
   AND d>e

The e<d and d>e parts are exactly equivalent to one another, so this could be rewritten as WHERE (e>c OR d>e) AND d>e. And since the right half of that OR clause is now guaranteed to be true for any row that passes the filter, you can further logically simplify it as WHERE (e>c OR true) AND d>e, and then to WHERE true and d>e and then simply to WHERE d>e, cutting out the OR subclause entirely.

Granted, this is just a test suite, so I don’t expect it to be representative of actual real-world code, but it makes me wonder. Is there any reason someone would write a query like that? Am I missing something in my logic, or is the OR subclause entirely redundant and meaningless here?



You need to sign in to view this answers

Exit mobile version