93 Pages written from the cache to the backing file.
5 Clean pages forced from the cache.
13 Dirty pages forced from the cache.
0 Dirty buffers written by trickle-sync thread.
130 Current clean buffer count.
4 Current dirty buffer count.
</pre>
<p>The statistics for this cache say that there have been 4,273 requests of
the cache, and only 116 of those requests required an I/O from disk. This
means that the cache is working well, yielding a 97% cache hit rate. The
<ahref="../api_reference/C/db_stat.html"class="olink">db_stat</a> utility will present these statistics both for the cache
as a whole and for each file within the cache separately.</p>
</div>
<divclass="sect2"lang="en"xml:lang="en">
<divclass="titlepage">
<div>
<div>
<h3class="title"><aid="am_conf_byteorder"></a>Selecting a byte order</h3>
</div>
</div>
</div>
<p>Database files created by Berkeley DB can be created in either little- or
big-endian formats. The byte order used for the underlying database
is specified by calling the <ahref="../api_reference/C/dbset_lorder.html"class="olink">DB->set_lorder()</a> method. If no order
is selected, the native format of the machine on which the database is
created will be used.</p>
<p>Berkeley DB databases are architecture independent, and any format database can
be used on a machine with a different native format. In this case, as
each page that is read into or written from the cache must be converted
to or from the host format, and databases with non-native formats will
incur a performance penalty for the run-time conversion.</p>
<p>
<spanclass="bold">
<strong>It is important to note that the Berkeley DB access methods do no data
conversion for application specified data. Key/data pairs written on a
little-endian format architecture will be returned to the application
exactly as they were written when retrieved on a big-endian format
architecture.</strong>
</span>
</p>
</div>
<divclass="sect2"lang="en"xml:lang="en">
<divclass="titlepage">
<div>
<div>
<h3class="title"><aid="am_conf_dup"></a>Duplicate data items</h3>
</div>
</div>
</div>
<p>
The Btree and Hash access methods support the creation of multiple data
items for a single key item. By default, multiple data items are not
permitted, and each database store operation will overwrite any
previous data item for that key. To configure Berkeley DB for
duplicate data items, call the <ahref="../api_reference/C/dbset_flags.html"class="olink">DB->set_flags()</a> method with the <ahref="../api_reference/C/dbset_flags.html#dbset_flags_DB_DUP"class="olink">DB_DUP</a>
flag. Only one copy of the key will be stored for each set of
duplicate data items. If the Btree access method comparison routine
returns that two keys compare equally, it is undefined which of the two
keys will be stored and returned from future database operations.
</p>
<p>
By default, Berkeley DB stores duplicates in the order in which they
were added, that is, each new duplicate data item will be stored after
any already existing data items. This default behavior can be
overridden by using the <ahref="../api_reference/C/dbcput.html"class="olink">DBC->put()</a> method and one of the <ahref="../api_reference/C/dbcput.html#dbcput_DB_AFTER"class="olink">DB_AFTER</a>,
<ahref="../api_reference/C/dbcput.html#dbcput_DB_BEFORE"class="olink">DB_BEFORE</a>, <ahref="../api_reference/C/dbcput.html#dbcput_DB_KEYFIRST"class="olink">DB_KEYFIRST</a> or <ahref="../api_reference/C/dbcput.html#dbcput_DB_KEYLAST"class="olink">DB_KEYLAST</a> flags. Alternatively,
Berkeley DB may be configured to sort duplicate data items.
</p>
<p>
When stepping through the database sequentially, duplicate data items
will be returned individually, as a key/data pair, where the key item
only changes after the last duplicate data item has been returned. For
this reason, duplicate data items cannot be accessed using the <ahref="../api_reference/C/dbget.html"class="olink">DB->get()</a>
method, as it always returns the first of the duplicate data items.
Duplicate data items should be retrieved using a Berkeley DB cursor
interface such as the <ahref="../api_reference/C/dbcget.html"class="olink">DBC->get()</a> method.
</p>
<p>
There is a flag that permits applications to request the following data
item only if it <spanclass="bold"><strong>is</strong></span> a duplicate data
item of the current entry, see <ahref="../api_reference/C/dbcget.html#dbcget_DB_NEXT_DUP"class="olink">DB_NEXT_DUP</a> for more information.
There is a flag that permits applications to request the following data
item only if it <spanclass="bold"><strong>is not</strong></span> a duplicate
data item of the current entry, see <ahref="../api_reference/C/dbcget.html#dbcget_DB_NEXT_NODUP"class="olink">DB_NEXT_NODUP</a> and <ahref="../api_reference/C/dbcget.html#dbcget_DB_PREV_NODUP"class="olink">DB_PREV_NODUP</a>
for more information.
</p>
<p>
It is also possible to maintain duplicate records in sorted order.
Sorting duplicates will significantly increase performance when
searching them and performing equality joins — both of which are
common operations when using secondary indices. To configure Berkeley
DB to sort duplicate data items, the application must call the
<ahref="../api_reference/C/dbset_flags.html"class="olink">DB->set_flags()</a> method with the <ahref="../api_reference/C/dbset_flags.html#dbset_flags_DB_DUPSORT"class="olink">DB_DUPSORT</a> flag. Note that <ahref="../api_reference/C/dbset_flags.html#dbset_flags_DB_DUPSORT"class="olink">DB_DUPSORT</a>
automatically turns on the <ahref="../api_reference/C/dbset_flags.html#dbset_flags_DB_DUP"class="olink">DB_DUP</a> flag for you, so you do not
have to also set that flag; however, it is not an error to also set <ahref="../api_reference/C/dbset_flags.html#dbset_flags_DB_DUP"class="olink">DB_DUP</a>
when configuring for sorted duplicate records.
</p>
<p>
When configuring sorted duplicate records, you can also specify a
custom comparison function using the <ahref="../api_reference/C/dbset_dup_compare.html"class="olink">DB->set_dup_compare()</a> method. If
the <ahref="../api_reference/C/dbset_flags.html#dbset_flags_DB_DUPSORT"class="olink">DB_DUPSORT</a> flag is given, but no comparison routine is specified,
then Berkeley DB defaults to the same lexicographical sorting used for
Btree keys, with shorter items collating before longer items.
</p>
<p>
If the duplicate data items are unsorted, applications may store
identical duplicate data items, or, for those that just like the way it
<spanclass="bold"><strong>It is an error to attempt to store identical
duplicate data items when duplicates are being stored in a sorted
order.</strong></span> Any such attempt results in the
error message "Duplicate data items are not supported with sorted
data" with a <codeclass="literal">DB_KEYEXIST</code> return code.
</p>
<p>
Note that you can suppress the error message "Duplicate data items are
not supported with sorted data" by using the <ahref="../api_reference/C/dbput.html#put_DB_NODUPDATA"class="olink">DB_NODUPDATA</a> flag. Use
of this flag does not change the database's basic behavior; storing
duplicate data items in a database configured for sorted duplicates is
still an error and so you will continue to receive the
<codeclass="literal">DB_KEYEXIST</code> return code if you try to do that.
</p>
<p>
For further information on how searching and insertion behaves in the
presence of duplicates (sorted or not), see the <ahref="../api_reference/C/dbget.html"class="olink">DB->get()</a><ahref="../api_reference/C/dbput.html"class="olink">DB->put()</a>,
<ahref="../api_reference/C/dbcget.html"class="olink">DBC->get()</a> and <ahref="../api_reference/C/dbcput.html"class="olink">DBC->put()</a> documentation.
<p>Berkeley DB allocates memory for returning key/data pairs and statistical
information which becomes the responsibility of the application.
There are also interfaces where an application will allocate memory
which becomes the responsibility of Berkeley DB.</p>
<p>On systems in which there may be multiple library versions of the
standard allocation routines (notably Windows NT), transferring memory
between the library and the application will fail because the Berkeley DB
library allocates memory from a different heap than the application
uses to free it, or vice versa. To avoid this problem, the
<ahref="../api_reference/C/envset_alloc.html"class="olink">DB_ENV->set_alloc()</a> and <ahref="../api_reference/C/dbset_alloc.html"class="olink">DB->set_alloc()</a> methods can be used to
give Berkeley DB references to the application's allocation routines.</p>