Changes

Jump to navigation Jump to search
1,826 bytes added ,  19:02, 16 October 2017
no edit summary
With {{Command|CREATE INDEX}} and {{Function|Database|db:optimize}}, new selective indexing options will ba applied to an existing database.
 
==Enforce Rewritings==
 
In various cases, existing index structures will not be utilized by the query optimizer. This is usually the case if the name of the database is not a static string (e.g., because it is bound to a variable or passed on as argument of a function call). Furthermore, several candidates for index rewritings may exist, and the query optimizer may decide for a rewriting that turns out to be suboptimal.
 
With {{Version|9.0}}, the {{Option|ENFORCEINDEX}} option was introduced, which allows you to enforce certain index rewritings. While the option can be globally enabled, it is usually better to supply it as [[XQuery Extensions#Pragmas|Pragma]]. Two examples:
 
* In the query below, 10 databases will be addressed. If it is known in advance that these databases contain an up-to-date text index, the index rewriting can be enforced as follows:
 
<pre class="brush:xquery">
(# db:enforceindex #) {
for $n in 1 to 10
let $db := 'persons' || $n
return db:open($db)//person[name/text() = 'John']
}
</pre>
 
* The following query contains two predicates that may both be rewritten for index access. If the automatically chosen rewriting is known not to be optimal, another index rewriting can enforced by surrounding the specific expression with the pragma:
 
<pre class="brush:xquery">
db:open('factbook')//country
[(# db:enforceindex #) {
@population > '10000000' and
@population < '10999999'
}]
[religions/text() = 'Protestant']
</pre>
 
Please note that:
 
* The enforcement of index rewritings gives you no guarantee that an index will be used. There are many expressions that cannot be rewritten for index access.
* If you have more than one enforce pragma in a single path expression, only the first will be considered.
=Custom Index Structures=
=Changelog=
 
;Version 9.0
 
* Added: [[#Enforce Rewritings|Enforce Rewritings]]
;Version 8.4
Bureaucrats, editor, reviewer, Administrators
13,550

edits

Navigation menu