Changes

Jump to navigation Jump to search
1,940 bytes added ,  23:26, 20 May 2013
no edit summary
This article describes the [[Storage Layout]] of the main database table.
 
==Node Table==
 
BaseX stores all XML nodes in a flat table. The node table of a database can be displayed via the [[Commands#INFO STORAGE|INFO STORAGE]] command:
 
<pre>
$ basex -c"create db db <xml>HiThere</xml>" -c"info storage"
 
PRE DIS SIZ ATS ID NS KIND CONTENT
-----------------------------------------
0 1 3 1 0 0 DOC db.xml
1 1 2 1 1 0 ELEM xml
2 1 1 1 2 0 TEXT HiThere
</pre>
 
The ''PRE'' value of a node represents the order in which the XML nodes are visited by a SAX parser. It is actually not stored in the database; instead, it is implicitly given by the table position. As a result, it will change whenever a node with a smaller ''pre'' values is added to or deleted from a database.
 
Each database node has a persistent ''ID'' vaule, which remains valid after update operations, and which is referenced by the index structures. If no updates have been performed on a database, the ''PRE'' and ''ID'' values are identical. This also applies if new nodes are attached to the end of the database. If nodes are deleted or inserted somewhere else, the values diverge, as shown in the next example:
 
<pre>
$ basex -c"create db db <xml>HiThere</xml>" -q"insert node <b/> before /xml" -c"info storage"
 
PRE DIS SIZ ATS ID NS KIND CONTENT
-----------------------------------------
0 1 4 1 0 0 DOC db.xml
1 1 1 1 3 0 ELEM b
2 2 2 1 1 0 ELEM xml
3 1 1 1 2 0 TEXT HiThere
</pre>
 
The [[Database Module#db:node-pre]] and [[Database Module#db:node-id]] functions can be called to retrieve the ''PRE'' and ''ID'' values of a node. [[Database Module#db:open-pre]] and [[Database Module#db:open-id]] can be used to retrieve a specific node. ''ID'' lookups can be expensive; the [[Options#UPDINDEX|UPDINDEX]] option can be turned on to build an additional index and speed up the process.
 
==Block Storage==
BaseX logically splits the {{Code|tbl.basex}} file into blocks with length 4096 bytes, i.e. each block can have max 256 records each with length 16 bytes. The records within a block are sorted by their pre value (which, therefore, can be implicitly determined and need not be saved).
Bureaucrats, editor, reviewer, Administrators
13,550

edits

Navigation menu