A method for processing queries is provided. A first representation of a
query is generated, where the query includes a certain operator that is
to be performed based on an XPath expression that is expandable into
multiple location paths. The first representation of the query is
rewritten into a second representation that corresponds to an equivalent
query, where rewriting the first representation includes expanding the
XPath expression into the plurality of location paths and, based on the
certain operator, including a plurality of operators in the second
representation, where the plurality of operators include: a first set of
operators that is to be performed based on each of the plurality of
location paths, and a second set of operators that is to be performed
based on data returned from at least one operator included in the first
set of operators. The query may thereafter be executed based on the
second representation. The second representation may be further rewritten
to third representation depending on the physical storage of XML.