A program storage device readable by a computer, tangibly embodying a program of instructions executable by the computer to perform method steps for optimizing an SQL query in a computer having a memory, the SQL query being performed by the computer to retrieve data from a relational database stored in an electronic storage device coupled to the computer, the method comprising the steps of:
- (a) generating an expression tree for the query in the memory of the computer;
- (b) removing projection operations from the expression tree in the memory of the computer by moving the projection operations to a top node of the expression tree;
- (c) generating projection sets and required sets for the expression tree in the memory of the computer;
- and
- (d) enumerating plans for the expression tree in the memory of the computer, wherein the enumerated plans contain reorderings of the projection operations and binary operations in accordance with the projection sets and required sets.