1. A computer-implemented method comprising: based on one or more path expressions that identify nodes that have corresponding index entries in an index, a DBMS maintaining: the index that contains index entries for each of a set of nodes that are defined by index metadata, wherein the index metadata includes the one or more path expressions that identify nodes that have corresponding index entries in the index; the index also including index entries for ancestor nodes of each node in the set of nodes, wherein the union of the set of nodes and all ancestor nodes comprises less than all nodes within a collection of XML documents; and the DBMS receiving a query that includes a particular path expression; based on the index metadata, the DBMS automatically determining at query compilation time whether the index may be used to evaluate the query; wherein the DBMS automatically determining whether the index can be used comprises inspecting the index metadata to determine whether the nodes identified by the particular path expression are within the set of nodes indexed by the index; in response to determining that the index may be used to evaluate the query, evaluating the query using the index; and sending query results; wherein the method is performed by one or more computing devices.