Patent attributes
A database engine receives a human-readable database query that includes a plurality of conditional expressions. The database engine parses the database query to build an operator tree that includes a subtree corresponding to each of the conditional expressions. The database engine identifies a subexpression that appears in two or more of the conditional expressions. The subexpression is executed conditionally. The database engine hoists the subexpression outside of the conditional expression so that it is executed unconditionally. The database engine modifies the operator tree to specify computation of a value for the subexpression a first time and to reuse the computed value when the subexpression is subsequently encountered. The database engine executes the modified operator tree to form a result set corresponding to the database query, thereby evaluating the subexpression only a single time for each row of input data and returns the result set.