Changes

Jump to navigation Jump to search
1,284 bytes added ,  15:10, 17 April 2012
no edit summary
This article is part of the [[Advanced User's Guide]] and introduces the available index structures, which may are utilized by the query optimizer to rewrite expressions and speed up querying by orders of magnitudesquery evaluation.
==Index Structures== CurrentlyThe examples in this article are based on the [http://files.basex.org/xml/factbook.xml factbook.xml] document. To see how a query is rewritten, please turn on the following index structures exist [[GUI#Visualizations|Info View]] in BaseX:the GUI or use the [[Startup_Options#BaseX_Standalone|-V flag]] on command line.
===Structural Indexes===
Structural indexes will always be present and cannot be dropped by the user:
* '''Tag/Attribute ==Name Index''': All element and attribute names are automatically indexed and enriched with statistical information.==
* '''Path Summary''': Unique paths The name index contains all element and attribute names of a database, and the fixed-size index ids are stored in the main database table. If a document or collection database is updated, new names are referenced by the path automatically added. The indexis further enriched with statistical information, which is applied e.g. to rewrite descendant to more specific child stepswill get out-of-dated after new updates.
* '''Document Index''': This The name index caches references is applied to all document nodes in a database. It provides fast access to single documents in large database instances.pre-evaluate location steps that will never yield results:
<pre class===Value Indexes==="brush:xquery"> (: will be rewritten to an empty sequence :)/non-existing-name</pre>
Value indexes can be dropped and created by the user:==Path Index==
* The path index (also called ''path summary'Text Index''': This ) stores all distinct paths of the documents in the database. It also contains additional statistical information. Currently, the index speeds up equality tests and simple range queries on text nodes in XPath location steps with predicateswill get out-of-dated after new updates.
* '''Attribute Index''': This The path index speeds up equality tests and simple range queries on attribute value in XPath location is applied to rewrite descendant steps to multiple child steps with predicates.Child steps can be evaluated faster, as less nodes have to be accessed:
* '''[[Full-Text|Full-Text Index]]'<pre class="brush:xquery"> doc('factbook.xml')//province,(: This index speeds up queries using the {{Mono|contains text}} keyword. Internally, BaseX handles two different index structures: the default index sorts all keys alphabetically by their character length. It is particularly fast if fuzzy searches are performed. The second index is a compressed trie structure, which needs slightly more memory, but is specialized on wildcard searcheswill be rewritten to... :)doc('factbook.xml')/mondial/country/province</pre>
With The paths statistics are e.g. used to pre-evaluate the {{Mono|count()}} function: <pre class="brush:xquery"> (: will be rewritten and pre-evaluated by the path index :)count( doc('factbook')//country )</pre> ==Document Index== The document index contains references to the {{MarkMono|pre}} values of all document nodes. It speeds up the access to specific documents in a database, and it will be automatically updated when updates are performed. The following query will be sped up by the document index: <pre class="brush:xquery"> db:open('DatabaseWithLotsOfDocuments')</pre> =Value Indexes= Value indexes can be optionally created and dropped by the user. The text and attribute index will be created by default: ==Text Index== This index speeds up string-based equality tests and (since {{Version |7.2.1}}) range queries on text nodes. The [[Options#UPDINDEX|UPDINDEX]] option can be activated to keep this index up-to-date. The following queries will all be rewritten for index access: <pre class="brush:xquery"> //*[text() = 'Germany'],doc('factbook.xml')//name[. = 'Germany'], a new database option was introduced db:open('factbook')//country[.//city/name = 'Hanoi']/name</pre> ==Attribute Index== Similar to support the text index, this index speeds up string-based tests on attribute values. The [[Options#UPDINDEX|incremental indexingUPDINDEX]] option can be activated to keep this index up-to-date. The following queries will all be rewritten for index access: <pre class="brush:xquery"> //country[@car_code = 'J'],//province[@* = 'Hokkaido']//name,//sea[@depth > '2100' and @depth < '4000']</pre> ==Full-Text Index== The [[Full-Text]] index speeds up queries using the {{Mono|contains text}} expression. Internally, two index structures are provided: the default index sorts all keys alphabetically by their character length. It is particularly fast if fuzzy searches are performed. The second index is a compressed trie structure, which needs slightly more memory, but is specialized on wildcard searches. Both index structures will be merged in a future version of texts and attributesBaseX.
==Example Queries==
The following queries are examples for expressions that will be optimized for index access (provided that the relevant index exists in a particular database):
===Name/Path Index===
* {{Mono|//address}} is rewritten to {{Mono|addressbook/address}} if all {{Mono|address}} elements have an {{Mono|addressbook}} element as their only ancestor.
* {{Mono|/non-existing-name}} is rewritten to an empty sequence
===Text Index=== * <code>//node()[If the full-text() = 'Usability']</code>* <code>//div[p = 'Usability' or p = 'Testing']</code>* <code>path/to/relevant[text() = 'Usability Testing']/and/so/on</code>index exists, the following queries will all be rewritten for index access:
===Attribute Index=== * <code>//node()[@align pre class= 'right']</code> * <code>descendant"brush::elem[@id = '1']</code>* <code>range/query[@id &gt;= 1 and @id &lt;= 5]</codexquery"> ===Full-Text Index=== * <code>//node[text() contains text 'Usability']<country/code>* <code>//nodename[text() contains text 'Usebilitiand' using fuzzy]</code> ,* <code>//bookreligions[chapter . contains text ({ 'webCatholic' ftor , 'WWWRoman' } using no stemming) ftand 'diversity' using stemming case insensitive distance at most 5 2 words]</codepre>
[[Category:Internals]]
Bureaucrats, editor, reviewer, Administrators
13,554

edits

Navigation menu