A method for optimizing queries is described. A query, which includes a
first expression for determining whether each of a set of values
evaluates to NULL or NOT NULL, is received. At compile-time, a first
representation of the query is generated, where the first representation
indicates that the query is to be performed based on the first
expression. Based on the first expression, a second expression is
determined. The second expression is such that the first expression would
evaluate to any NOT NULL value if and only if the second expression would
evaluate to any NOT NULL value. The second expression, when evaluated, is
much more computationally efficient compared with the evaluation of the
first expression. Based on the first representation, a second
representation of the query is generated, where the second representation
indicates that the query is to be performed based on the second
expression. Thereafter, the query is executed based on the second
representation.