Changes

Jump to navigation Jump to search
2,866 bytes added ,  17:18, 26 October 2017
==Name Index==
The name index contains all element and attribute references to the names of a database, all elements and the fixed-size index ids are stored attributes in the main database table. If a database is updated, new names are automatically added. Furthermore, the index is enriched with It contains some basic statistical information, such as the distinct (categorical) or minimum and maximum values number of its elements and attributes. The maximum number occurrence of categories to store per a name can be changed via [[Options#MAXCATS|MAXCATS]]. The index are discarded after [[#Updates|database updates]].
The name index is e.g. applied to pre-evaluate discard location steps that will never yield results:
<pre class="brush:xquery">
The contents of the name indexes can be directly accessed with the XQuery functions [[Index Module#index:element-names|index:element-names]] and [[Index Module#index:attribute-names|index:attribute-names]].
 
If a database is updated, new names will be added incrementally, but the statistical information will get out-dated.
==Path Index==
The path index (which is also called ''path summary'' or ''data guide'') stores all distinct paths of the documents in the database. It contains similar additional statistical information , such as the number of occurrence of a path, its distinct string values, and the minimum/maximum of numeric values. The maximum number of distinct values to store per name indexcan be changed via {{Option|MAXCATS}}. The index Distinct values are discarded after [[#Updates|database updates]]also stored for elements and attributes of numeric type.
The Various queries will be evaluated much faster if an up-to-date path index is applied to rewrite descendant available (as can be observed when opening the [[GUI#Visualizations|Info View]]): * Descendant steps will be rewritten to multiple child steps. Child steps can be are evaluated faster, as fewer nodes have to be accessedtraversed:
<pre class="brush:xquery">
</pre>
* The paths statistics are e.g. used to pre-evaluate the {{Code|fn:count}} functionwill be pre-evaluated by looking up the number in the index:
<pre class="brush:xquery">
count(doc(: will 'factbook')//country)</pre> * The distinct values of elements or attributes can be rewritten and pre-evaluated by looked up in the path index as well: <pre class="brush:)xquery"> countdistinct-values( docdb:open('factbook')//country religions)
</pre>
The contents of the path index can be directly accessed with the XQuery function [[Index Module#index:facets|index:facets]].
 
If a database is updated, the statistics in the path index will be invalidated.
==Document Index==
Matching text nodes can be directly requested from the index with the XQuery function {{Function|Database|db:text}}. The index contents can be accessed via {{Function|Index|index:text}}.
The {{Option|UPDINDEX}} option can be activated to keep this index up-to-date., for example: <pre class="brush:xquery">db:optimize( 'mydb', true(), map { 'updindex':true(), 'textindex': true(), 'textinclude':'id' })</pre>
===Range Queries===
Attribute nodes can directly be retrieved from the index with the XQuery functions {{Function|Database|db:attribute}} and {{Function|Database|db:attribute-range}}. The index contents can be accessed with {{Function|Index|index:attributes}}.
The [[Options#UPDINDEX{{Option|UPDINDEX]] }} option can be activated to keep this index up-to-date.
==Token Index==
 
{{Mark|Introduced with Version 8.4:}}
In many XML dialects, such as HTML or DITA, multiple tokens are stored in attribute values. The token index can be created to speed up the retrieval of these tokens. The XQuery functions {{Code|fn:contains-token}}, {{Code|fn:tokenize}} and {{Code|fn:idref}} are rewritten for index access whenever possible. If a token index exists, it will e.g. be utilized for the following queries:
The index provides support for the following full-text features (the values can be changed in the GUI or via the {{Command|SET}} command):
* '''Stemming''': tokens are stemmed before being indexed (see option: {{Option|STEMMING}})* '''Case Sensitive''': tokens are indexed in case-sensitive mode (see option: {{Option|CASESENS}})* '''Diacritics''': diacritics are indexed as well (see option: {{Option|DIACRITICS}})* '''Stopword List''': a stop word list can be defined to reduce the number of indexed tokens (see option: {{Option|STOPWORDS}})* '''Language''': see [[Full-Text#Languages|Languages]] for more details (see option: {{Option|LANGUAGE}})
The options that have been used for creating the full-text index will also be applied to the optimized full-text queries. However, the defaults can be overwritten if you supply options in your query. For example, if words were stemmed in the index, and if the query can be rewritten for index access, the query terms will be stemmed as well, unless stemming is not explicitly disabled. This is demonstrated in the following [[Commands#Command_Scripts|Command Script]]:
==Selective Indexing==
 
{{Mark|Updated with Version 8.4:}} {{Code|TOKENINCLUDE}} option added
Value indexing can be restricted to specific elements and attributes. The nodes to be indexed can be restricted via the {{Option|TEXTINCLUDE}}, {{Option|ATTRINCLUDE}}, {{Option|TOKENINCLUDE}} and {{Option|FTINCLUDE}} options. The options take a list of name patterns, which are separated by commas. The following name patterns are supported:
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 option should only be enabled if the addressed databases exist, have all required index structures and are up-to-date (otherwise, you will be given an error message).
* 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=
=Performance=
 
{{Mark|Updated with Version 8.4:}}
If main memory runs out while creating a value index, the current index structures will be partially written to disk and eventually merged. If the memory heuristics fail for some reason (i.e., because multiple index operations run at the same time, or because the applied JVM does not support explicit garbage collections), a fixed index split sizes may be chosen via the {{Option|SPLITSIZE}} option.
=Updates=
Updates in BaseX Generally, update operations are generally very fastin BaseX. By default, because the index structures will be invalidated by updates. As ; as a result, subsequent queries that benefit from index structures may be executed more slowly than before the updateslow down after updates. There are different alternatives to cope with this:
* After the execution of one or more update operations, the {{Command|OPTIMIZE}} command or the {{Function|Database|db:optimize}} function can be called to rebuild the index structures.
* The {{Option|UPDINDEX}} option can be activated before creating or optimizing the database. As a result, the text, attribute and token indexes will be incrementally updated after each database update. Please note that incremental updates are not available for the full-text index and database statistics. This is also explains why the up-to-date UPTODATE flag, which is e.g. displayed via {{Command|INFO DB}} or {{Function|Database|db:info}}, will be set to {{Code|false}} until the database will be optimized again(various optimizations won’t be triggered. For example, count(//item) can be extremely fast if all meta data is up-to-date.* The {{Option|AUTOOPTIMIZE}} option can be enabled before creating or optimizing the database. All outdated index structures and statistics will then be recreated after each database update. This option should only be used done for small and medium-sized databases.* Both options can be used side by side: {{Option|UPDINDEX}} will take care that the value index structures will be updated as part of the actual update operation. {{Option|AUTOOPTIMIZE}} will update the remaining data structures (full-text index, database statistics).
=Changelog=
 
;Version 9.0
 
* Added: [[#Enforce Rewritings|Enforce Rewritings]]
 
;Version 8.4
 
* Updated: [[#Name Index|Name Index]], [[#Path Index|Path Index]]
;Version 8.4
Bureaucrats, editor, reviewer, Administrators
13,550

edits

Navigation menu