Optimization is provided for database statements involving XML data, e.g.,
XPath and XQuery, which operate over views that use aggregate set
operators, e.g., UNION ALL. As part of a "view merge" stage of query
transformation, the query that operates over the view is merged with a
query that defines the view. One or more expressions (e.g., operators,
predicates, virtual table constructs) from the query that operates over
the view are then "pushed down" to operate on the individual underlying
XML data constructs. "Branch elimination" is performed based on the
structure of the view and the query acting over the view, based on which
it is possible to determine whether any of the sub-queries, if executed,
would result in the return of zero rows. If so, then such branches are
eliminated from the transformed query, leaving a reduced set of data
containers on which to execute the query.