1 .\" Copyright (c) 1990, 1993
2 .\" The Regents of the University of California. All rights reserved.
4 .\" %%%LICENSE_START(BSD_4_CLAUSE_UCB)
5 .\" Redistribution and use in source and binary forms, with or without
6 .\" modification, are permitted provided that the following conditions
8 .\" 1. Redistributions of source code must retain the above copyright
9 .\" notice, this list of conditions and the following disclaimer.
10 .\" 2. Redistributions in binary form must reproduce the above copyright
11 .\" notice, this list of conditions and the following disclaimer in the
12 .\" documentation and/or other materials provided with the distribution.
13 .\" 3. All advertising materials mentioning features or use of this software
14 .\" must display the following acknowledgement:
15 .\" This product includes software developed by the University of
16 .\" California, Berkeley and its contributors.
17 .\" 4. Neither the name of the University nor the names of its contributors
18 .\" may be used to endorse or promote products derived from this software
19 .\" without specific prior written permission.
21 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 .\" @(#)btree.3 8.4 (Berkeley) 8/18/94
36 .TH BTREE 3 2020-12-21 "" "Linux Programmer's Manual"
39 btree \- btree database access method
43 #include <sys/types.h>
49 This page documents interfaces provided in glibc up until version 2.1.
50 Since version 2.2, glibc no longer provides these interfaces.
51 Probably, you are looking for the APIs provided by the
57 is the library interface to database files.
58 One of the supported file formats is btree files.
59 The general description of the database access methods is in
61 this manual page describes only the btree-specific information.
63 The btree data structure is a sorted, balanced tree structure storing
64 associated key/data pairs.
66 The btree access-method-specific data structure provided to
70 include file as follows:
76 unsigned int cachesize;
80 int (*compare)(const DBT *key1, const DBT *key2);
81 size_t (*prefix)(const DBT *key1, const DBT *key2);
87 The elements of this structure are as follows:
90 The flag value is specified by ORing any of the following values:
94 Permit duplicate keys in the tree, that is,
95 permit insertion if the key to be
96 inserted already exists in the tree.
97 The default behavior, as described in
99 is to overwrite a matching key when inserting a new key or to fail if
105 flag is overridden by the
109 flag is specified, attempts to insert duplicate keys into
112 If the database contains duplicate keys, the order of retrieval of
113 key/data pairs is undefined if the
115 routine is used, however,
117 routine calls with the
119 flag set will always return the logical
120 "first" of any group of duplicate keys.
124 A suggested maximum size (in bytes) of the memory cache.
127 advisory, and the access method will allocate more memory rather than fail.
128 Since every search examines the root page of the tree, caching the most
129 recently used pages substantially improves access time.
130 In addition, physical writes are delayed as long as possible, so a moderate
131 cache can reduce the number of I/O operations significantly.
132 Obviously, using a cache increases (but only increases) the likelihood of
133 corruption or lost data if the system crashes while a tree is being modified.
136 is 0 (no size is specified), a default cache is used.
139 The maximum number of keys which will be stored on any single page.
140 Not currently implemented.
141 .\" The maximum number of keys which will be stored on any single page.
142 .\" Because of the way the btree data structure works,
144 .\" must always be greater than or equal to 2.
147 .\" is 0 (no maximum number of keys is specified), the page fill factor is
148 .\" made as large as possible (which is almost invariably what is wanted).
151 The minimum number of keys which will be stored on any single page.
152 This value is used to determine which keys will be stored on overflow
153 pages, that is, if a key or data item is longer than the pagesize divided
154 by the minkeypage value, it will be stored on overflow pages instead
155 of in the page itself.
158 is 0 (no minimum number of keys is specified), a value of 2 is used.
161 Page size is the size (in bytes) of the pages used for nodes in the tree.
162 The minimum page size is 512 bytes and the maximum page size is 64\ KiB.
165 is 0 (no page size is specified), a page size is chosen based on the
166 underlying filesystem I/O block size.
169 Compare is the key comparison function.
170 It must return an integer less than, equal to, or greater than zero if the
171 first key argument is considered to be respectively less than, equal to,
172 or greater than the second key argument.
173 The same comparison function must be used on a given tree every time it
177 is NULL (no comparison function is specified), the keys are compared
178 lexically, with shorter keys considered less than longer keys.
181 Prefix is the prefix comparison function.
182 If specified, this routine must return the number of bytes of the second key
183 argument which are necessary to determine that it is greater than the first
185 If the keys are equal, the key length should be returned.
186 Note, the usefulness of this routine is very data-dependent, but, in some
187 data sets can produce significantly reduced tree sizes and search times.
190 is NULL (no prefix function is specified),
192 no comparison function is specified, a default lexical comparison routine
196 is NULL and a comparison routine is specified, no prefix comparison is
200 The byte order for integers in the stored database metadata.
201 The number should represent the order as an integer; for example,
202 big endian order would be the number 4,321.
205 is 0 (no order is specified), the current host order is used.
207 If the file already exists (and the
209 flag is not specified), the
210 values specified for the arguments
216 in favor of the values used when the tree was created.
218 Forward sequential scans of a tree are from the least key to the greatest.
220 Space freed up by deleting key/data pairs from the tree is never reclaimed,
221 although it is normally made available for reuse.
222 This means that the btree storage structure is grow-only.
223 The only solutions are to avoid excessive deletions, or to create a fresh
224 tree periodically from a scan of an existing one.
226 Searches, insertions, and deletions in a btree will all complete in
227 O lg base N where base is the average fill factor.
228 Often, inserting ordered data into btrees results in a low fill factor.
229 This implementation has been modified to make ordered insertion the best
230 case, resulting in a much better than normal page fill factor.
234 access method routines may fail and set
236 for any of the errors specified for the library routine
239 Only big and little endian byte order is supported.
246 .IR "The Ubiquitous B-tree" ,
247 Douglas Comer, ACM Comput. Surv. 11, 2 (June 1979), 121-138.
249 .IR "Prefix B-trees" ,
250 Bayer and Unterauer, ACM Transactions on Database Systems, Vol. 2, 1
253 .IR "The Art of Computer Programming Vol. 3: Sorting and Searching" ,
254 D.E. Knuth, 1968, pp 471-480.