• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /asuswrt-rt-n18u-9.0.0.4.380.2695/release/src-rt-6.x.4708/router/db-4.8.30/docs/programmer_reference/
1<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3<html xmlns="http://www.w3.org/1999/xhtml">
4  <head>
5    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
6    <title>Hash access method specific configuration</title>
7    <link rel="stylesheet" href="gettingStarted.css" type="text/css" />
8    <meta name="generator" content="DocBook XSL Stylesheets V1.73.2" />
9    <link rel="start" href="index.html" title="Berkeley DB Programmer's Reference Guide" />
10    <link rel="up" href="am_conf.html" title="Chapter��2.�� Access Method Configuration" />
11    <link rel="prev" href="bt_conf.html" title="Btree access method specific configuration" />
12    <link rel="next" href="rq_conf.html" title="Queue and Recno access method specific configuration" />
13  </head>
14  <body>
15    <div class="navheader">
16      <table width="100%" summary="Navigation header">
17        <tr>
18          <th colspan="3" align="center">Hash access method specific configuration</th>
19        </tr>
20        <tr>
21          <td width="20%" align="left"><a accesskey="p" href="bt_conf.html">Prev</a>��</td>
22          <th width="60%" align="center">Chapter��2.��
23		Access Method Configuration
24        </th>
25          <td width="20%" align="right">��<a accesskey="n" href="rq_conf.html">Next</a></td>
26        </tr>
27      </table>
28      <hr />
29    </div>
30    <div class="sect1" lang="en" xml:lang="en">
31      <div class="titlepage">
32        <div>
33          <div>
34            <h2 class="title" style="clear: both"><a id="hash_conf"></a>Hash access method specific configuration</h2>
35          </div>
36        </div>
37      </div>
38      <div class="toc">
39        <dl>
40          <dt>
41            <span class="sect2">
42              <a href="hash_conf.html#am_conf_h_ffactor">Page fill factor</a>
43            </span>
44          </dt>
45          <dt>
46            <span class="sect2">
47              <a href="hash_conf.html#am_conf_h_hash">Specifying a database hash</a>
48            </span>
49          </dt>
50          <dt>
51            <span class="sect2">
52              <a href="hash_conf.html#am_conf_h_nelem">Hash table size</a>
53            </span>
54          </dt>
55        </dl>
56      </div>
57      <p>
58    There are a series of configuration tasks which you can perform when
59    using the Hash access method.  They are described in the following sections.
60</p>
61      <div class="sect2" lang="en" xml:lang="en">
62        <div class="titlepage">
63          <div>
64            <div>
65              <h3 class="title"><a id="am_conf_h_ffactor"></a>Page fill factor</h3>
66            </div>
67          </div>
68        </div>
69        <p>The density, or page fill factor, is an approximation of the number of
70keys allowed to accumulate in any one bucket, determining when the hash
71table grows or shrinks.  If you know the average sizes of the keys and
72data in your data set, setting the fill factor can enhance performance.
73A reasonable rule to use to compute fill factor is:</p>
74        <pre class="programlisting">(pagesize - 32) / (average_key_size + average_data_size + 8)</pre>
75        <p>The desired density within the hash table can be specified by calling
76the <a href="../api_reference/C/dbset_h_ffactor.html" class="olink">DB-&gt;set_h_ffactor()</a> method.  If no density is specified, one will
77be selected dynamically as pages are filled.</p>
78      </div>
79      <div class="sect2" lang="en" xml:lang="en">
80        <div class="titlepage">
81          <div>
82            <div>
83              <h3 class="title"><a id="am_conf_h_hash"></a>Specifying a database hash</h3>
84            </div>
85          </div>
86        </div>
87        <p>The database hash determines in which bucket a particular key will reside.
88The goal of hashing keys is to distribute keys equally across the database
89pages, therefore it is important that the hash function work well with
90the specified keys so that the resulting bucket usage is relatively
91uniform.  A hash function that does not work well can effectively turn
92into a sequential list.</p>
93        <p>No hash performs equally well on all possible data sets.  It is possible
94that applications may find that the default hash function performs poorly
95with a particular set of keys.  The distribution resulting from the hash
96function can be checked using the <a href="../api_reference/C/db_stat.html" class="olink">db_stat utility</a>.  By comparing the
97number of hash buckets and the number of keys, one can decide if the entries
98are hashing in a well-distributed manner.</p>
99        <p>The hash function for the hash table can be specified by calling the
100<a href="../api_reference/C/dbset_h_hash.html" class="olink">DB-&gt;set_h_hash()</a> method.  If no hash function is specified, a default
101function will be used.  Any application-specified hash function must
102take a reference to a <a href="../api_reference/C/db.html" class="olink">DB</a> object, a pointer to a byte string and
103its length, as arguments and return an unsigned, 32-bit hash value.</p>
104      </div>
105      <div class="sect2" lang="en" xml:lang="en">
106        <div class="titlepage">
107          <div>
108            <div>
109              <h3 class="title"><a id="am_conf_h_nelem"></a>Hash table size</h3>
110            </div>
111          </div>
112        </div>
113        <p>When setting up the hash database, knowing the expected number of elements
114that will be stored in the hash table is useful.  This value can be used
115by the Hash access method implementation to more accurately construct the
116necessary number of buckets that the database will eventually require.</p>
117        <p>The anticipated number of elements in the hash table can be specified by
118calling the <a href="../api_reference/C/dbset_h_nelem.html" class="olink">DB-&gt;set_h_nelem()</a> method.  If not specified, or set too low,
119hash tables will expand gracefully as keys are entered, although a slight
120performance degradation may be noticed.  In order for the estimated number
121of elements to be a useful value to Berkeley DB, the <a href="../api_reference/C/dbset_h_ffactor.html" class="olink">DB-&gt;set_h_ffactor()</a> method
122must also be called to set the page fill factor.</p>
123      </div>
124    </div>
125    <div class="navfooter">
126      <hr />
127      <table width="100%" summary="Navigation footer">
128        <tr>
129          <td width="40%" align="left"><a accesskey="p" href="bt_conf.html">Prev</a>��</td>
130          <td width="20%" align="center">
131            <a accesskey="u" href="am_conf.html">Up</a>
132          </td>
133          <td width="40%" align="right">��<a accesskey="n" href="rq_conf.html">Next</a></td>
134        </tr>
135        <tr>
136          <td width="40%" align="left" valign="top">Btree access method specific configuration��</td>
137          <td width="20%" align="center">
138            <a accesskey="h" href="index.html">Home</a>
139          </td>
140          <td width="40%" align="right" valign="top">��Queue and Recno access method specific configuration</td>
141        </tr>
142      </table>
143    </div>
144  </body>
145</html>
146