]>
Commit | Line | Data |
---|---|---|
fea681da MK |
1 | .\" Copyright (c) 1990, 1993 |
2 | .\" The Regents of the University of California. All rights reserved. | |
3 | .\" | |
4 | .\" Redistribution and use in source and binary forms, with or without | |
5 | .\" modification, are permitted provided that the following conditions | |
6 | .\" are met: | |
7 | .\" 1. Redistributions of source code must retain the above copyright | |
8 | .\" notice, this list of conditions and the following disclaimer. | |
9 | .\" 2. Redistributions in binary form must reproduce the above copyright | |
10 | .\" notice, this list of conditions and the following disclaimer in the | |
11 | .\" documentation and/or other materials provided with the distribution. | |
12 | .\" 3. All advertising materials mentioning features or use of this software | |
13 | .\" must display the following acknowledgement: | |
14 | .\" This product includes software developed by the University of | |
15 | .\" California, Berkeley and its contributors. | |
16 | .\" 4. Neither the name of the University nor the names of its contributors | |
17 | .\" may be used to endorse or promote products derived from this software | |
18 | .\" without specific prior written permission. | |
19 | .\" | |
20 | .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | |
21 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
22 | .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
23 | .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
24 | .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
25 | .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
26 | .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
27 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
28 | .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
29 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
30 | .\" SUCH DAMAGE. | |
31 | .\" | |
32 | .\" @(#)btree.3 8.4 (Berkeley) 8/18/94 | |
33 | .\" | |
df21098d | 34 | .TH BTREE 3 2012-04-23 "" "Linux Programmer's Manual" |
fea681da MK |
35 | .\".UC 7 |
36 | .SH NAME | |
37 | btree \- btree database access method | |
38 | .SH SYNOPSIS | |
39 | .nf | |
40 | .ft B | |
41 | #include <sys/types.h> | |
42 | #include <db.h> | |
43 | .ft R | |
44 | .fi | |
45 | .SH DESCRIPTION | |
df21098d MK |
46 | .IR "Note well" : |
47 | This page documents interfaces provided in glibc up until version 2.1. | |
48 | Since version 2.2, glibc no longer provides these interfaces. | |
49 | Probably, you are looking for the APIs provided by the | |
50 | .I libdb | |
51 | library instead. | |
52 | ||
fea681da | 53 | The routine |
fb186734 | 54 | .BR dbopen (3) |
fea681da MK |
55 | is the library interface to database files. |
56 | One of the supported file formats is btree files. | |
57 | The general description of the database access methods is in | |
31e9a9ec | 58 | .BR dbopen (3), |
fea681da MK |
59 | this manual page describes only the btree specific information. |
60 | .PP | |
61 | The btree data structure is a sorted, balanced tree structure storing | |
62 | associated key/data pairs. | |
63 | .PP | |
64 | The btree access method specific data structure provided to | |
fb186734 | 65 | .BR dbopen (3) |
e5056894 MK |
66 | is defined in the |
67 | .I <db.h> | |
68 | include file as follows: | |
088a639b | 69 | .in +4n |
ce4b0e57 | 70 | .nf |
e5056894 | 71 | |
fea681da | 72 | typedef struct { |
aeb4b1fc MK |
73 | unsigned long flags; |
74 | unsigned int cachesize; | |
75 | int maxkeypage; | |
76 | int minkeypage; | |
77 | unsigned int psize; | |
78 | int (*compare)(const DBT *key1, const DBT *key2); | |
79 | size_t (*prefix)(const DBT *key1, const DBT *key2); | |
80 | int lorder; | |
fea681da | 81 | } BTREEINFO; |
ce4b0e57 MK |
82 | .fi |
83 | .in | |
fea681da MK |
84 | .PP |
85 | The elements of this structure are as follows: | |
86 | .TP | |
e5056894 | 87 | .I flags |
cebca1bd | 88 | The flag value is specified by ORing any of the following values: |
fea681da MK |
89 | .RS |
90 | .TP | |
628d8d62 | 91 | .B R_DUP |
75b94dc3 MK |
92 | Permit duplicate keys in the tree, that is, |
93 | permit insertion if the key to be | |
fea681da MK |
94 | inserted already exists in the tree. |
95 | The default behavior, as described in | |
31e9a9ec | 96 | .BR dbopen (3), |
fea681da | 97 | is to overwrite a matching key when inserting a new key or to fail if |
628d8d62 MK |
98 | the |
99 | .B R_NOOVERWRITE | |
100 | flag is specified. | |
101 | The | |
102 | .B R_DUP | |
103 | flag is overridden by the | |
104 | .B R_NOOVERWRITE | |
105 | flag, and if the | |
40d6f0f0 MK |
106 | .B R_NOOVERWRITE |
107 | flag is specified, attempts to insert duplicate keys into | |
fea681da MK |
108 | the tree will fail. |
109 | .IP | |
110 | If the database contains duplicate keys, the order of retrieval of | |
111 | key/data pairs is undefined if the | |
112 | .I get | |
113 | routine is used, however, | |
114 | .I seq | |
628d8d62 MK |
115 | routine calls with the |
116 | .B R_CURSOR | |
117 | flag set will always return the logical | |
40d6f0f0 | 118 | "first" of any group of duplicate keys. |
fea681da MK |
119 | .RE |
120 | .TP | |
e5056894 | 121 | .I cachesize |
fea681da MK |
122 | A suggested maximum size (in bytes) of the memory cache. |
123 | This value is | |
836f07c1 | 124 | .I only |
fea681da MK |
125 | advisory, and the access method will allocate more memory rather than fail. |
126 | Since every search examines the root page of the tree, caching the most | |
127 | recently used pages substantially improves access time. | |
128 | In addition, physical writes are delayed as long as possible, so a moderate | |
129 | cache can reduce the number of I/O operations significantly. | |
130 | Obviously, using a cache increases (but only increases) the likelihood of | |
131 | corruption or lost data if the system crashes while a tree is being modified. | |
132 | If | |
133 | .I cachesize | |
134 | is 0 (no size is specified) a default cache is used. | |
135 | .TP | |
e5056894 | 136 | .I maxkeypage |
fea681da MK |
137 | The maximum number of keys which will be stored on any single page. |
138 | Not currently implemented. | |
139 | .\" The maximum number of keys which will be stored on any single page. | |
140 | .\" Because of the way the btree data structure works, | |
141 | .\" .I maxkeypage | |
142 | .\" must always be greater than or equal to 2. | |
143 | .\" If | |
144 | .\" .I maxkeypage | |
145 | .\" is 0 (no maximum number of keys is specified) the page fill factor is | |
146 | .\" made as large as possible (which is almost invariably what is wanted). | |
147 | .TP | |
e5056894 | 148 | .I minkeypage |
fea681da MK |
149 | The minimum number of keys which will be stored on any single page. |
150 | This value is used to determine which keys will be stored on overflow | |
75b94dc3 | 151 | pages, that is, if a key or data item is longer than the pagesize divided |
fea681da MK |
152 | by the minkeypage value, it will be stored on overflow pages instead |
153 | of in the page itself. | |
154 | If | |
155 | .I minkeypage | |
156 | is 0 (no minimum number of keys is specified) a value of 2 is used. | |
157 | .TP | |
e5056894 | 158 | .I psize |
fea681da MK |
159 | Page size is the size (in bytes) of the pages used for nodes in the tree. |
160 | The minimum page size is 512 bytes and the maximum page size is 64K. | |
161 | If | |
162 | .I psize | |
163 | is 0 (no page size is specified) a page size is chosen based on the | |
164 | underlying file system I/O block size. | |
165 | .TP | |
e5056894 | 166 | .I compare |
fea681da MK |
167 | Compare is the key comparison function. |
168 | It must return an integer less than, equal to, or greater than zero if the | |
169 | first key argument is considered to be respectively less than, equal to, | |
170 | or greater than the second key argument. | |
171 | The same comparison function must be used on a given tree every time it | |
172 | is opened. | |
173 | If | |
174 | .I compare | |
175 | is NULL (no comparison function is specified), the keys are compared | |
176 | lexically, with shorter keys considered less than longer keys. | |
177 | .TP | |
e5056894 | 178 | .I prefix |
fea681da MK |
179 | Prefix is the prefix comparison function. |
180 | If specified, this routine must return the number of bytes of the second key | |
181 | argument which are necessary to determine that it is greater than the first | |
182 | key argument. | |
183 | If the keys are equal, the key length should be returned. | |
a43eed0c | 184 | Note, the usefulness of this routine is very data-dependent, but, in some |
fea681da MK |
185 | data sets can produce significantly reduced tree sizes and search times. |
186 | If | |
187 | .I prefix | |
188 | is NULL (no prefix function is specified), | |
836f07c1 | 189 | .I and |
fea681da MK |
190 | no comparison function is specified, a default lexical comparison routine |
191 | is used. | |
192 | If | |
193 | .I prefix | |
194 | is NULL and a comparison routine is specified, no prefix comparison is | |
195 | done. | |
196 | .TP | |
e5056894 | 197 | .I lorder |
fea681da | 198 | The byte order for integers in the stored database metadata. |
c13182ef | 199 | The number should represent the order as an integer; for example, |
fea681da MK |
200 | big endian order would be the number 4,321. |
201 | If | |
202 | .I lorder | |
203 | is 0 (no order is specified) the current host order is used. | |
204 | .PP | |
c8fe3fa2 MK |
205 | If the file already exists (and the |
206 | .B O_TRUNC | |
207 | flag is not specified), the | |
c4bb193f | 208 | values specified for the arguments |
e5056894 MK |
209 | .IR flags , |
210 | .I lorder | |
211 | and | |
212 | .I psize | |
213 | are ignored | |
fea681da MK |
214 | in favor of the values used when the tree was created. |
215 | .PP | |
216 | Forward sequential scans of a tree are from the least key to the greatest. | |
217 | .PP | |
218 | Space freed up by deleting key/data pairs from the tree is never reclaimed, | |
219 | although it is normally made available for reuse. | |
220 | This means that the btree storage structure is grow-only. | |
221 | The only solutions are to avoid excessive deletions, or to create a fresh | |
222 | tree periodically from a scan of an existing one. | |
223 | .PP | |
224 | Searches, insertions, and deletions in a btree will all complete in | |
225 | O lg base N where base is the average fill factor. | |
226 | Often, inserting ordered data into btrees results in a low fill factor. | |
227 | This implementation has been modified to make ordered insertion the best | |
228 | case, resulting in a much better than normal page fill factor. | |
229 | .SH ERRORS | |
230 | The | |
231 | .I btree | |
232 | access method routines may fail and set | |
233 | .I errno | |
234 | for any of the errors specified for the library routine | |
31e9a9ec | 235 | .BR dbopen (3). |
e37e3282 MK |
236 | .SH BUGS |
237 | Only big and little endian byte order is supported. | |
47297adb | 238 | .SH SEE ALSO |
31e9a9ec MK |
239 | .BR dbopen (3), |
240 | .BR hash (3), | |
241 | .BR mpool (3), | |
242 | .BR recno (3) | |
173fe7e7 | 243 | |
fea681da MK |
244 | .IR "The Ubiquitous B-tree" , |
245 | Douglas Comer, ACM Comput. Surv. 11, 2 (June 1979), 121-138. | |
173fe7e7 | 246 | |
fea681da MK |
247 | .IR "Prefix B-trees" , |
248 | Bayer and Unterauer, ACM Transactions on Database Systems, Vol. 2, 1 | |
249 | (March 1977), 11-26. | |
173fe7e7 | 250 | |
c13182ef | 251 | .IR "The Art of Computer Programming Vol. 3: Sorting and Searching" , |
fea681da | 252 | D.E. Knuth, 1968, pp 471-480. |