=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>)
<noinclude>'''A little thank you...'''<br><small>The following data types are used for {{{1}}}.<br>hugs, {{{2}}}</small></noinclude>specifying the storage layout:
<div {| class="noprintwikitable" style|- valign="float:center; border:1px solid blue;width:200px;backgroundtop"! Type! Description! Example (native → hex integers)|-color:#F5F5F5;padding:3px;valign="top">| {{Type|Num}}| Compressed integer (1-5 bytes), specified in [[Imagehttps:Example//github.com/BaseXdb/basex/blob/master/basex-core/src/main/java/org/basex/util/Num.java Num.jpgjava]|left{{Code|80px15}} → {{Code|Example sunflower image]] '''A little thank you...''' 0F}}; {{Code|511}} → {{Code|41 FF}}<br /><small>for |- valign="top"| {{Type|Token}}| Length ({{Type|Num}}) and bytes of UTF8 byte representation| {{Code|Hello}} → {{Code|05 48 65 6c 6c 6f}}|- valign="top"| {{Type|Double}}| Number, stored as token| {reason{Code|123}} → {{Code|03 31 32 33}}|- valign="top"| {{Type|Boolean}}| Boolean (1byte, {{Code|00}} or {{Code|01}})| {{Code|true}}→ {{Code|01}}|- valign="top"| {{Type|Nums}}. <br />hugs, {{Type|Tokens}}, {signature{Type|Doubles}}| Arrays of values, introduced with the number of entries|{{Code|1,2}} → {{2Code|02 01 31 01 32}}|- valign="top"| {{Type|TokenSet}}| Key array ({{Type|Tokens}}<), next/bucket/small>size arrays (3x {{Type|Nums}})|</div>|}
=Database Files=
==infThe following tables illustrate the layout of the BaseX database files. All files are suffixed with {{Code|.basex==}}.
==Metadata, Name/Path/Doc Indexes: {{Code|inf}}== {| class="wikitable" width|- valign="100%top"|-
! Description
! Format
! Method|-| valign='top' | '''Disk Data'''| Database meta information| valign='"top' | [https://github.com/BaseXdb/basex/blob/master/src/main/java/org/basex/data/DiskData.java DiskData()]|-"| valign='top' | '''1. Meta DataMetadata'''| 1. Key/value pairs, suffixed by empty key in no particular order ({{Type|Token}}/{{Type|Token}}):<br /> • Examples: {{Code|FNAME}}, {{Code|TIME}}, {{Code|SIZE}}, ...<codebr/> • {{Code|PERM</code> }} → User PermissionsNumber of users ({{Type| valign='top' | [https:Num}}), and name/password/github.compermission values for each user ({{Type|Token}}/BaseXdb{{Type|Token}}/basex/blob/master/src/main/java/org/basex/data/MetaData.java MetaData.read({{Type|Num}})]<br/>[https://github2.com/BaseXdb/basex/blob/master/src/main/java/org/basex/core/Users.java Users.read()]Empty key as finalizer|-| valign='"top' "| '''2. Main memory indexes'''| 1. Key/value pairs, suffixed by empty key in no particular order ({{Type|Token}}/{{Type|Token}}):<br /> • <code>{{Code|TAGS</code> }} → Tag Element Name Index<br /> • <code>{{Code|ATTS</code> }} → Attribute Name Index<br /> • <code>{{Code|PATH</code> }} → Path Index<br /> • <code>{{Code|NS</code> }} → Namespaces<br /> • <code>{{Code|DOCS</code> }} → Document Index| valign='top' | [https:<br//github>2.com/BaseXdb/basex/blob/master/src/main/java/org/basex/data/DiskData.java DiskData()]Empty key as finalizer|-| valign='"top' "| '''2.1. a) Name Index'''<br/>Element/attribute names| 1. Token set, enriched with statistical information:storing all names ({{Type|TokenSet}})<br />12. Token setOne StatsKey instance per entry: key array (<code>Tokens</code>), next/bucket/size arrays (<code>Nums</code>)<br />2.1. Content kind (<code>{{Type|Num</code>}}):<br />2.1.1. Number: min/max (<code>{{Type|Doubles</code>}})<br />2.1.2. Category: number of entries (<code>{{Type|Num</code>}}), entries (<code>{{Type|Tokens</code>}})<br />2.32. Number of entries (<code>{{Type|Num</code>}})<br />2.43. Leaf flag (<code>{{Type|Boolean</code>}})<br />2.54. Maximum text length (<code>{{Type|Double</code>}}; legacy, could be <code>{{Type|Num</code>}})| - valign='"top' | [https://github.com/BaseXdb/basex/blob/master/src/main/java/org/basex/index/Names.java Names()]<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/src/main/java/org/basex/index/StatsKey.java StatsKey()]|-"| valign='top' | '''2.2. b) Path Index'''| 1. Flag for path definition (<code>{{Type|Boolean</code>}}, always <code>{{Code|true</code>}}; legacy)<br/>2. PathNode:<br/>2.1. Name reference (<code>{{Type|Num</code>}})<br/>2.2. Node kind (<code>{{Type|Num</code>}})<br/>2.3. Number of occurrences (<code>{{Type|Num</code>}})<br/>2.4. Number of children (<code>{{Type|Num</code>}})<br/>2.5. <code>{{Type|Double</code>}}; legacy, can be reused or discarded<br/>2.6. Recursive generation of child nodes (→ 2)| - valign='"top' | [https://github.com/BaseXdb/basex/blob/master/src/main/java/org/basex/index/path/PathSummary.java PathSummary()]<br/>[https://github.com/BaseXdb/basex/blob/master/src/main/java/org/basex/index/path/PathNode.java PathNode()]|-"| valign='top' | '''2.3. c) Namespaces'''| 1. Token set, storing prefixes (<code>{{Type|TokenSet</code>}})<br/>2. Token set, storing URIs (<code>{{Type|TokenSet</code>}})<br/>3. NSNode:<br/>3.1. pre value (<code>{{Type|Num</code>}})<br/>3.2. References to prefix/URI pairs (<code>{{Type|Nums</code>}})<br/>3.3. Number of children (<code>{{Type|Num</code>}})<br/>3.4. Recursive generation of child nodes (→ 3)<code>| - valign="top"| '''2 d) Document Index''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/src/main/java/org/basex/data/NSNode.java NSNodeArray of integers, representing the distances between all document pre values ({{Type|Nums}})]
|}
==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]].
==Document Path Index: {{Code|pth}}==
Provides an index of all the document paths in the database. For databases with a large number of paths this file can be quite large so it is only generated the first time a function requesting a path lookup is run. For databases where path lookups are never used this file will not exist.
'''Note:''' On Windows/Mac systems this file is case insensitive (all paths are lower case). On UNIX-like systems this file is case sensitive. The behaviour of path look ups will vary between systems. Copying this file between system types may lead to unexpected behaviour.
==ID/Pre Mapping: {{Code|idp}}==
This file is only created if incremental indexing (UPDINDEX) is enabled for a database. It is used to provide a quick look up of the pre value for a database node id.
==Full-Text Fuzzy Index: {{Code|ftxx}}, {{Code|ftxy}}, {{Code|ftxz}}==
...may soon be reimplemented.