eXist-db/exist — pull request #146 by wolfgangmm (2014-02-09 20:59:52+00:00)
Title: Redesign query rewriting for index operations

Split query rewriting for the range index into two parts:

1. at compile time: inject OptimizeFieldPragma around potential candidates for range index lookups and rewrite filter expressions to use range functions. OptimizeFieldPragma handles complex index definitions which may involve multiple filters to be merged into one index lookup. In this case the entire XPath is replaced by a function call. Simple index lookups are handled by the range:* functions.
2. check at runtime if optimization can be applied (index is available) or not. Fall back to default processing if no index or only a legacy range index is available. Backwards compatibility with old range index is preserved.

This approach should be more expensive than the compile-time optimization we used before, but has the advantage that queries do not need to be recompiled if the collection configuration changes. The pragma and the range functions will fall back to default processing automatically.

The overhead for rewriting the query was not measurable in my tests (below the threshold of the profiler).