Skip to content

Commit 6441402

Browse files
committed
Add docs about new range index functions.
1 parent 1c4fa01 commit 6441402

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

data/newrangeindex.xml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
12
<?xml-stylesheet type="text/css" href="file:/Applications/oxygen/frameworks/docbook/css/docbook.css"?>
23
<book>
34
<bookinfo>
@@ -239,5 +240,46 @@
239240
thus still be faster to split the expression into two parts and do the name check
240241
first.</section>
241242
</section>
243+
<section>
244+
<title>Using Index Functions</title>
245+
<para>Internally the query optimizer will rewrite range lookup expressions into
246+
optimized function calls into the <code>range</code> module (namespace
247+
<code>http://exist-db.org/xquery/range</code>). This happens transparently and
248+
you'll never see the function calls. However, for debugging and testing it is
249+
sometimes useful to be able to use the corresponding functions directly. There are
250+
two sets of functions: one for simple range index lookups, and one for indexes on
251+
fields.</para>
252+
<para>Given the following index configuration:</para>
253+
<example>
254+
<title>Some Indexes on Shakespeare</title>
255+
<programlisting language="xml">&lt;range&gt;
256+
&lt;create qname="SPEAKER" type="xs:string"/&gt;
257+
&lt;create qname="SPEECH"&gt;
258+
&lt;field name="stagedir" type="xs:string" match="//STAGEDIR"/&gt;
259+
&lt;field name="line" type="xs:string" match="LINE" case="no"/&gt;
260+
&lt;/create&gt;
261+
&lt;/range&gt;</programlisting>
262+
</example>
263+
<para>A query:</para>
264+
<synopsis language="xquery">//SPEECH[SPEAKER="HAMLET"]</synopsis>
265+
<para>translates into:</para>
266+
<synopsis language="xquery">//SPEECH[range:eq(SPEAKER, "HAMLET")]</synopsis>
267+
<para>If the index is defined on an element with fields, the entire sub-expression, i.e. the context path and all its filters,
268+
is rewritten into a single function call. For example, take:</para>
269+
<synopsis language="xquery">collection("/db/apps/demo/data")//SPEECH[.//STAGEDIR = "Aside"]</synopsis>
270+
<para>is replaced with</para>
271+
<synopsis language="xquery">collection("/db/apps/demo/data")/range:field-eq("stagedir", "Aside")</synopsis>
272+
<para>Because the index root is defined on <sgmltag>SPEECH</sgmltag>, the function will always return
273+
<sgmltag>SPEECH</sgmltag> elements.</para>
274+
<para>If multiple filters are used and each of them has a corresponding field definition, they are combined into one call:</para>
275+
<synopsis language="xquery">collection("/db/apps/demo/data")/range:field-eq(("stagedir", "line"), "Aside", "what do you read, my lord?")</synopsis>
276+
<para>Note that while the field names are specified in a sequence, we add one parameter for every value to look up. This way it is possible
277+
to specify more than one value for each parameter by passing in a sequence.</para>
278+
<para>Because different operators might be used inside the filters, the query engine will actually rewrite the expression to the
279+
following:</para>
280+
<synopsis language="xquery">collection("/db/apps/demo/data")/range:field(("stagedir", "line"), ("eq", "eq"), "Aside", "what do you read, my lord?")</synopsis>
281+
<para>This is not easy to read, but efficient, and users will normally not see this function call anyway. However, it sometimes helps to know what the
282+
optimizer is supposed to do and try it out explicitely.</para>
283+
</section>
242284
</chapter>
243285
</book>

0 commit comments

Comments
 (0)