A method, computer readable medium, and system for optimizing a query in a
relational database processing system is disclosed. The present invention
relates to a query rewrite optimization method for eliminating a
redundant join and equivalent subquery in an SQL query before generation
and selection of the optimal query execution plan. The method of the
present invention includes evaluating the query to identify a join
predicate joining a sub-expression of the query to itself, and
determining whether a row set producible from a first set of references
of the query to the sub-expression is subsumed by a row set producible
from a second set of references of the query to the sub-expression. Based
on such evaluation and determination, the query may be reformed to
eliminate the join predicate and the second quantifier. A further
determination of the removability of the second quantifier may be
required such as by evaluating a cardinality constraint when query output
cardinality is material.