Database Reference
In-Depth Information
Using Indexes
Once they are defined, eXist tries to use the indexes as efficiently as possible, often by
silently optimizing XPath expressions. You can also use them by explicitly calling cer‐
tain extension functions. This section will tell you how to get the most out of your
indexes.
Using the Structural Index
The structural index is a core part of eXist and cannot be avoided, even if you want
to. However, the way it is implemented, as an index of qualified names, leads to some
surprising effects. Being aware of this can help you write more efficient code.
When eXist evaluates a query like //title/author , it performs two lookups in the
structural index: all title elements and all author elements (in the full database!). It
then performs a structural join between these sets to determine which author ele‐
ments are children of title elements. Because of the way internal node identifiers
are built up (see “Dynamic Level Numbering of Nodes” on page 80 ), this is extremely
efficient.
As a consequence, some of the common wisdom about XPath may not hold true for
eXist. For instance, more specific queries like /a/b/c/d/e are often presented in text‐
books as being more efficient than //e , but since every step in an XQuery expression
would cause eXist to perform a join, the fewer steps the better. In eXist, //e or /a//e
is more efficient than /a/b/c/d/e .
The structural index is also used for looking up identifiers with the id function (find‐
ing nodes with a matching xml:id attribute or with a matching attribute that is
explicitly marked as of type ID in an attached DTD).
Using the Range Indexes
Range indexes are used automatically to optimize queries. For this to work, the fol‐
lowing conditions must be met:
• The data type of the range index must match the data type used in the query.
For instance, assume you have a range index of data type xs:integer defined on
attribute customerid . A query //Customer[@customerid eq '3456'] will not
use this index because your query uses string comparison. To make use of the
index, you need to rewrite this as //Customer[@customerid eq 3456] .
Search WWH ::




Custom Search