]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man3/btree.3
man*/: srcfix (Use .P instead of .PP or .LP)
[thirdparty/man-pages.git] / man3 / btree.3
CommitLineData
fea681da
MK
1.\" Copyright (c) 1990, 1993
2.\" The Regents of the University of California. All rights reserved.
3.\"
47009d5e 4.\" SPDX-License-Identifier: BSD-4-Clause-UC
fea681da
MK
5.\"
6.\" @(#)btree.3 8.4 (Berkeley) 8/18/94
7.\"
4c1c5274 8.TH btree 3 (date) "Linux man-pages (unreleased)"
fea681da
MK
9.\".UC 7
10.SH NAME
11btree \- btree database access method
b813014f
AC
12.SH LIBRARY
13Standard C library
14.RI ( libc ", " \-lc )
fea681da
MK
15.SH SYNOPSIS
16.nf
17.ft B
18#include <sys/types.h>
19#include <db.h>
20.ft R
21.fi
22.SH DESCRIPTION
df21098d 23.IR "Note well" :
b324e17d
AC
24This page documents interfaces provided up until glibc 2.1.
25Since glibc 2.2, glibc no longer provides these interfaces.
df21098d
MK
26Probably, you are looking for the APIs provided by the
27.I libdb
28library instead.
c6d039a3 29.P
fea681da 30The routine
fb186734 31.BR dbopen (3)
fea681da
MK
32is the library interface to database files.
33One of the supported file formats is btree files.
34The general description of the database access methods is in
31e9a9ec 35.BR dbopen (3),
76c637e1 36this manual page describes only the btree-specific information.
c6d039a3 37.P
fea681da
MK
38The btree data structure is a sorted, balanced tree structure storing
39associated key/data pairs.
c6d039a3 40.P
76c637e1 41The btree access-method-specific data structure provided to
fb186734 42.BR dbopen (3)
e5056894
MK
43is defined in the
44.I <db.h>
45include file as follows:
c6d039a3 46.P
088a639b 47.in +4n
e646a1ba 48.EX
fea681da 49typedef struct {
aeb4b1fc
MK
50 unsigned long flags;
51 unsigned int cachesize;
52 int maxkeypage;
53 int minkeypage;
54 unsigned int psize;
55 int (*compare)(const DBT *key1, const DBT *key2);
56 size_t (*prefix)(const DBT *key1, const DBT *key2);
57 int lorder;
fea681da 58} BTREEINFO;
b8302363 59.EE
ce4b0e57 60.in
c6d039a3 61.P
fea681da
MK
62The elements of this structure are as follows:
63.TP
e5056894 64.I flags
cebca1bd 65The flag value is specified by ORing any of the following values:
fea681da
MK
66.RS
67.TP
628d8d62 68.B R_DUP
75b94dc3
MK
69Permit duplicate keys in the tree, that is,
70permit insertion if the key to be
fea681da
MK
71inserted already exists in the tree.
72The default behavior, as described in
31e9a9ec 73.BR dbopen (3),
fea681da 74is to overwrite a matching key when inserting a new key or to fail if
628d8d62
MK
75the
76.B R_NOOVERWRITE
77flag is specified.
78The
79.B R_DUP
80flag is overridden by the
81.B R_NOOVERWRITE
82flag, and if the
40d6f0f0
MK
83.B R_NOOVERWRITE
84flag is specified, attempts to insert duplicate keys into
fea681da
MK
85the tree will fail.
86.IP
87If the database contains duplicate keys, the order of retrieval of
88key/data pairs is undefined if the
89.I get
90routine is used, however,
91.I seq
628d8d62
MK
92routine calls with the
93.B R_CURSOR
94flag set will always return the logical
40d6f0f0 95"first" of any group of duplicate keys.
fea681da
MK
96.RE
97.TP
e5056894 98.I cachesize
fea681da
MK
99A suggested maximum size (in bytes) of the memory cache.
100This value is
836f07c1 101.I only
fea681da
MK
102advisory, and the access method will allocate more memory rather than fail.
103Since every search examines the root page of the tree, caching the most
104recently used pages substantially improves access time.
105In addition, physical writes are delayed as long as possible, so a moderate
106cache can reduce the number of I/O operations significantly.
107Obviously, using a cache increases (but only increases) the likelihood of
108corruption or lost data if the system crashes while a tree is being modified.
109If
110.I cachesize
113839c3 111is 0 (no size is specified), a default cache is used.
fea681da 112.TP
e5056894 113.I maxkeypage
fea681da
MK
114The maximum number of keys which will be stored on any single page.
115Not currently implemented.
116.\" The maximum number of keys which will be stored on any single page.
117.\" Because of the way the btree data structure works,
118.\" .I maxkeypage
119.\" must always be greater than or equal to 2.
120.\" If
121.\" .I maxkeypage
113839c3 122.\" is 0 (no maximum number of keys is specified), the page fill factor is
fea681da
MK
123.\" made as large as possible (which is almost invariably what is wanted).
124.TP
e5056894 125.I minkeypage
fea681da
MK
126The minimum number of keys which will be stored on any single page.
127This value is used to determine which keys will be stored on overflow
75b94dc3 128pages, that is, if a key or data item is longer than the pagesize divided
fea681da
MK
129by the minkeypage value, it will be stored on overflow pages instead
130of in the page itself.
131If
132.I minkeypage
113839c3 133is 0 (no minimum number of keys is specified), a value of 2 is used.
fea681da 134.TP
e5056894 135.I psize
fea681da 136Page size is the size (in bytes) of the pages used for nodes in the tree.
ab5736e9 137The minimum page size is 512 bytes and the maximum page size is 64\ KiB.
fea681da
MK
138If
139.I psize
113839c3 140is 0 (no page size is specified), a page size is chosen based on the
9ee4a2b6 141underlying filesystem I/O block size.
fea681da 142.TP
e5056894 143.I compare
fea681da
MK
144Compare is the key comparison function.
145It must return an integer less than, equal to, or greater than zero if the
146first key argument is considered to be respectively less than, equal to,
147or greater than the second key argument.
148The same comparison function must be used on a given tree every time it
149is opened.
150If
151.I compare
152is NULL (no comparison function is specified), the keys are compared
153lexically, with shorter keys considered less than longer keys.
154.TP
e5056894 155.I prefix
fea681da
MK
156Prefix is the prefix comparison function.
157If specified, this routine must return the number of bytes of the second key
158argument which are necessary to determine that it is greater than the first
159key argument.
160If the keys are equal, the key length should be returned.
a43eed0c 161Note, the usefulness of this routine is very data-dependent, but, in some
fea681da
MK
162data sets can produce significantly reduced tree sizes and search times.
163If
164.I prefix
165is NULL (no prefix function is specified),
836f07c1 166.I and
fea681da
MK
167no comparison function is specified, a default lexical comparison routine
168is used.
169If
170.I prefix
171is NULL and a comparison routine is specified, no prefix comparison is
172done.
173.TP
e5056894 174.I lorder
fea681da 175The byte order for integers in the stored database metadata.
c13182ef 176The number should represent the order as an integer; for example,
fea681da
MK
177big endian order would be the number 4,321.
178If
179.I lorder
113839c3 180is 0 (no order is specified), the current host order is used.
c6d039a3 181.P
c8fe3fa2
MK
182If the file already exists (and the
183.B O_TRUNC
184flag is not specified), the
c4bb193f 185values specified for the arguments
e5056894 186.IR flags ,
d556548b 187.IR lorder ,
e5056894
MK
188and
189.I psize
190are ignored
fea681da 191in favor of the values used when the tree was created.
c6d039a3 192.P
fea681da 193Forward sequential scans of a tree are from the least key to the greatest.
c6d039a3 194.P
fea681da
MK
195Space freed up by deleting key/data pairs from the tree is never reclaimed,
196although it is normally made available for reuse.
197This means that the btree storage structure is grow-only.
198The only solutions are to avoid excessive deletions, or to create a fresh
199tree periodically from a scan of an existing one.
c6d039a3 200.P
fea681da
MK
201Searches, insertions, and deletions in a btree will all complete in
202O lg base N where base is the average fill factor.
203Often, inserting ordered data into btrees results in a low fill factor.
204This implementation has been modified to make ordered insertion the best
205case, resulting in a much better than normal page fill factor.
206.SH ERRORS
207The
208.I btree
209access method routines may fail and set
210.I errno
211for any of the errors specified for the library routine
31e9a9ec 212.BR dbopen (3).
e37e3282
MK
213.SH BUGS
214Only big and little endian byte order is supported.
47297adb 215.SH SEE ALSO
31e9a9ec
MK
216.BR dbopen (3),
217.BR hash (3),
218.BR mpool (3),
219.BR recno (3)
c6d039a3 220.P
fea681da
MK
221.IR "The Ubiquitous B-tree" ,
222Douglas Comer, ACM Comput. Surv. 11, 2 (June 1979), 121-138.
c6d039a3 223.P
fea681da
MK
224.IR "Prefix B-trees" ,
225Bayer and Unterauer, ACM Transactions on Database Systems, Vol. 2, 1
226(March 1977), 11-26.
c6d039a3 227.P
c13182ef 228.IR "The Art of Computer Programming Vol. 3: Sorting and Searching" ,
fea681da 229D.E. Knuth, 1968, pp 471-480.