Changes

Jump to navigation Jump to search
2,353 bytes added ,  19:06, 5 February 2016
=Version: 7This article is part of the [[Advanced User's Guide]]. It presents some low-level details on how data is stored in the database files.0=
==Data Types==* <code>Num</code>: compressed integer (1-5 bytes)* <code>Token</code>: length (<code>Num</code>) and bytes of UTF8 byte representation* <code>double</code>: number, stored as token* <code>boolean</code>: boolean (1 byte, <code>00</code> or <code>01</code>)
The following data types are used for specifying the storage layout: {| class="wikitable" width=inf"100%"|-! Type! Description! Example (native → hex integers)|-| {{Type|Num}}| Compressed integer (1-5 bytes), specified in [https://github.com/BaseXdb/basex/blob/master/basex-core/src/main/java/org/basex/util/Num.java Num.java]| {{Code|15}} → {{Code|0F}}; {{Code|511}} → {{Code|41 FF}}<br/>|-| {{Type|Token}}| Length ({{Type|Num}}) and bytes of UTF8 byte representation| {{Code|Hello}} → {{Code|05 48 65 6c 6c 6f}}|-| {{Type|Double}}| Number, stored as token| {{Code|123}} → {{Code|03 31 32 33}}|-| {{Type|Boolean}}| Boolean (1 byte, {{Code|00}} or {{Code|01}})| {{Code|true}} → {{Code|01}}|-| {{Type|Nums}}, {{Type|Tokens}}, {{Type|Doubles}}| Arrays of values, introduced with the number of entries| {{Code|1,2}} → {{Code|02 01 31 01 32}}|-| {{Type|TokenSet}}| Key array ({{Type|Tokens}}), next/bucket/size arrays (3x {{Type|Nums}})||} =Database Files= The following tables illustrate the layout of the BaseX database files. All files are suffixed with {{Code|.basex}}. ==Meta Data, Name/Path/Doc Indexes: {{Code|inf}}==
{| class="wikitable" width="100%"
! Method
|-
| valign='top' | '''Disk 1. Meta Data'''| Database meta information1. Key/value pairs, in no particular order ({{Type|Token}}/{{Type|Token}}):<br/>&nbsp; &bull; Examples: {{Code|FNAME}}, {{Code|TIME}}, {{Code|SIZE}}, ...<br />&nbsp; &bull; {{Code|PERM}} → Number of users ({{Type|Num}}), and name/password/permission values for each user ({{Type|Token}}/{{Type|Token}}/{{Type|Num}})<br/>2. Empty key as finalizer| valign='top' | [https://github.com/BaseXdb/basex/blob/master/basex-core/src/main/java/org/basex/data/DiskData.java DiskData()]<br/>[https://github.com/BaseXdb/basex/blob/master/basex-core/src/main/java/org/basex/data/MetaData.java MetaData()]<br/>[https://github.com/BaseXdb/basex/blob/master/basex-core/src/main/java/org/basex/core/Users.java Users()]
|-
| valign='top' | '''12. Meta DataMain memory indexes'''| Pairs of key1. Key/value tokenspairs, suffixed by empty keyin no particular order ({{Type|Token}}/{{Type|Token}}):<br />&nbsp; &bull; {{Code|TAGS}} → Element Name Index<codebr />PERM&nbsp; &bull; {{Code|ATTS}} → Attribute Name Index<br /code> &nbsp; &bull; {{Code|PATH}} User PermissionsPath Index<br />&nbsp; &bull; {{Code| valign='top' NS}} → Namespaces<br />&nbsp; &bull; {{Code| [https://github.com/BaseXdb/basex/blob/master/src/main/java/org/basex/data/MetaData.java MetaData.read()]DOCS}} → Document Index<br/>2. Empty key as finalizer| [https://github.com/BaseXdb/basex/blob/master/basex-core/src/main/java/org/basex/coredata/UsersDiskData.java Users.readDiskData()]
|-
| valign='top' | '''2. Main memory indexesa) Name Index'''<br/>Element/attribute names| Pairs of key/value tokens1. Token set, suffixed by empty key:storing all names ({{Type|TokenSet}})<br />&bull; <code>TAGS2. One StatsKey instance per entry:<br/code> → Tag Index2.1. Content kind ({{Type|Num}}):<br />&bull; <code>ATTS2.1.1. Number: min/max ({{Type|Doubles}})<br /code> → Attribute Index2.1.2. Category: number of entries ({{Type|Num}}), entries ({{Type|Tokens}})<br />&bull; <code>PATH2.2. Number of entries ({{Type|Num}})<br /code> → Path Index2.3. Leaf flag ({{Type|Boolean}})<br />&bull2.4. Maximum text length ({{Type|Double}}; <code>NS<legacy, could be {{Type|Num}})| [https://github.com/BaseXdb/basex/blob/master/basex-core/src/main/java/org/basex/index/code> → NamespacesNames.java Names()]<br />&bull; <code>DOCS[https://github.com/BaseXdb/basex/blob/master/basex-core/src/main/java/org/basex/util/hash/TokenSet.java TokenSet.read()]<br/code> → Document Index| valign='top' | [https://github.com/BaseXdb/basex/blob/master/basex-core/src/main/java/org/basex/dataindex/DiskDataStatsKey.java DiskDataStatsKey()]
|-
| valign='top' | '''2.1. Name b) Path Index'''<br/>Element/attribute names| Token set, enriched with statistical information:<br />1. Token set: key array Flag for path definition (<code>Tokens</code>){{Type|Boolean}}, next/bucket/size arrays (<code>Nums</code>always {{Code|true}}; legacy)<br />2. Content kind (<code>Num</code>)PathNode:<br />2.1. Number: min/max Name reference (<code>Doubles</code>{{Type|Num}})<br />2.2. Category: number of entries Node kind (<code>{{Type|Num</code>), entries (<code>Tokens</code>}})<br />2.3. Number of entries occurrences (<code>{{Type|Num</code>}})<br />2.4. Leaf flag Number of children (<code>Boolean</code>{{Type|Num}})<br />2.5. Maximum text length (<code>{{Type|Double</code>}}; legacy, could can be reused or discarded<code>Num<br/code>2.6. Recursive generation of child nodes (→ 2)| valign='top' | [https://github.com/BaseXdb/basex/blob/master/basex-core/src/main/java/org/basex/index/Namespath/PathSummary.java NamesPathSummary()]<br/>[https://github.com/BaseXdb/basex/blob/master/src/main/java/org/basex/util/hash/TokenSet.java TokenSet.read()]<br/>[https://github.com/BaseXdb/basex/blob/master-core/src/main/java/org/basex/index/StatsKeypath/PathNode.java StatsKeyPathNode()]
|-
| valign='top' | '''2.2. Path Indexc) Namespaces'''| 1. Flag for path definition Token set, storing prefixes ({{Type|TokenSet}})<code>Boolean<br/code>2. Token set, always <code>true</code>; legacystoring URIs ({{Type|TokenSet}})<br/>23. PathNodeNSNode:<br/>23.1. Name reference pre value (<code>{{Type|Num</code>}})<br/>23.2. Node kind References to prefix/URI pairs (<code>Num</code>{{Type|Nums}})<br/>23.3. Number of occurrences children (<code>{{Type|Num</code>}})<br/>23.4. Number of children (<code>Num</code>)<br/>2.5. <code>Double</code>; legacy, can be reused or discarded<br/>2.6. Recursive generation of child nodes (→ 23)<code>| valign='top' | [https://github.com/BaseXdb/basex/blob/master/basex-core/src/main/java/org/basex/index/pathdata/PathSummaryNamespaces.java PathSummaryNamespaces()]<br/>[https://github.com/BaseXdb/basex/blob/master/basex-core/src/main/java/org/basex/index/pathdata/PathNodeNSNode.java PathNodeNSNode()]
|-
| valign='top' | '''2.3. Namespacesd) Document Index'''| 1. Token setArray of integers, storing prefixes (<code>TokenSet</code>)<br/>2. Token set, storing URIs (<code>TokenSet</code>)<br/>3. NSNode:<br/>3.1. representing the distances between all document pre value values (<code>Num</code>)<br/>3.2. References to prefix/URI pairs (<code>{{Type|Nums</code>)<br/>3.3. Number of children (<code>Num</code>}})<br/>3.4. Recursive generation of child nodes (→ 3)<code>| valign='top' | [https://github.com/BaseXdb/basex/blob/master/src/main/java/org/basex/data/Namespaces.java Namespaces()]<br/>[https://github.com/BaseXdb/basex/blob/master-core/src/main/java/org/basex/dataindex/NSNodeDocIndex.java NSNodeDocIndex()]
|}
 
==Node Table: {{Code|tbl}}, {{Code|tbli}}==
 
* {{Code|tbl}}: Main database table, stored in blocks.
* {{Code|tbli}}: Database directory, organizing the database blocks.
 
Some more information on the [[Node Storage|node storage]] is available.
 
==Texts: {{Code|txt}}, {{Code|atv}}==
 
* {{Code|txt}}: Heap file for text values (document names, string values of texts, comments and processing instructions)
* {{Code|atv}}: Heap file for attribute values.
 
==Value Indexes: {{Code|txtl}}, {{Code|txtr}}, {{Code|atvl}}, {{Code|atvr}}==
 
'''Text Index:'''
* {{Code|txtl}}: Heap file with ID lists.
* {{Code|txtr}}: Index file with references to ID lists.
The '''Attribute Index''' is contained in the files {{Code|atvl}} and {{Code|atvr}}, the '''Token Index''' in {{Code|tokl}} and {{Code|tokr}}. All have the same layout.
 
For a more detailed discussion and examples of these file formats please see [[Index File Structure]].
 
==Full-Text Fuzzy Index: {{Code|ftxx}}, {{Code|ftxy}}, {{Code|ftxz}}==
 
...may soon be reimplemented.
Bureaucrats, editor, reviewer, Administrators
13,550

edits

Navigation menu