1<!--$Id: db_key_range.so,v 10.24 2007/10/24 16:06:06 bostic Exp $-->
2<!--Copyright (c) 1997,2008 Oracle.  All rights reserved.-->
3<!--See the file LICENSE for redistribution information.-->
4<html>
5<head>
6<title>Berkeley DB: DB-&gt;key_range</title>
7<meta name="description" content="Berkeley DB: An embedded database programmatic toolkit.">
8<meta name="keywords" content="embedded,database,programmatic,toolkit,btree,hash,hashing,transaction,transactions,locking,logging,access method,access methods,Java,C,C++">
9</head>
10<body bgcolor=white>
11<table width="100%"><tr valign=top>
12<td>
13<b>DB-&gt;key_range</b>
14</td>
15<td align=right>
16<a href="../api_c/api_core.html"><img src="../images/api.gif" alt="API"></a>
17<a href="../ref/toc.html"><img src="../images/ref.gif" alt="Ref"></a></td>
18</tr></table>
19<hr size=1 noshade>
20<tt>
21<b><pre>
22#include &lt;db.h&gt;
23<p>
24int
25DB-&gt;key_range(DB *db, DB_TXN *txnid,
26    DBT *key, DB_KEY_RANGE *key_range, u_int32_t flags);
27</pre></b>
28<hr size=1 noshade>
29<b>Description: DB-&gt;key_range</b>
30<p>The DB-&gt;key_range method returns an estimate of the proportion of keys
31that are less than, equal to, and greater than the specified key.  The
32underlying database must be of type Btree.</p>
33<p>The DB-&gt;key_range method fills in a structure of type DB_KEY_RANGE.  The
34following data fields are available from the DB_KEY_RANGE structure:</p>
35<br>
36<b>double less;</b><ul compact><li>A value between 0 and 1, the proportion of keys less than the specified
37key.</ul>
38<b>double equal;</b><ul compact><li>A value between 0 and 1, the proportion of keys equal to the specified
39key.</ul>
40<b>double greater;</b><ul compact><li>A value between 0 and 1, the proportion of keys greater than the
41specified key.</ul>
42<br>
43<p>Values are in the range of 0 to 1; for example, if the field
44<b>less</b> is 0.05, 5% of the keys in the database are less than the
45<b>key</b> parameter.  The value for <b>equal</b> will be zero if
46there is no matching key, and will be non-zero otherwise.</p>
47<p>The DB-&gt;key_range method
48returns a non-zero error value on failure
49and 0 on success.
50</p>
51<b>Parameters</b> <br>
52 <b>key</b><ul compact><li>The key <a href="../api_c/dbt_class.html">DBT</a> operated on.</ul>
53 <b>key_range</b><ul compact><li>The estimates are returned in the <b>key_range</b> parameter, which
54contains three elements of type double: <b>less</b>, <b>equal</b>, and
55<b>greater</b>.  Values are in the range of 0 to 1; for example, if the
56field <b>less</b> is 0.05, 5% of the keys in the database are less than
57the <b>key</b> parameter.  The value for <b>equal</b> will be zero if
58there is no matching key, and will be non-zero otherwise.</ul>
59 <b>txnid</b><ul compact><li>If the operation is part of an application-specified transaction, the
60<b>txnid</b> parameter is a transaction handle returned from
61<a href="../api_c/txn_begin.html">DB_ENV-&gt;txn_begin</a>; if the operation is part of a Berkeley DB Concurrent Data Store group, the
62<b>txnid</b> parameter is a handle returned from
63<a href="../api_c/env_cdsgroup_begin.html">DB_ENV-&gt;cdsgroup_begin</a>; otherwise NULL.
64If no transaction handle is
65specified, but the
66operation occurs in a transactional
67database,
68the operation will be implicitly transaction protected.
69The DB-&gt;key_range method does not retain the locks it acquires for the
70life of the transaction, so estimates may not be repeatable.</ul>
71 <b>flags</b><ul compact><li>The <b>flags</b> parameter is currently unused, and must be set to 0.</ul>
72<br>
73<br><b>Errors</b>
74<p>The DB-&gt;key_range method
75may fail and return one of the following non-zero errors:</p>
76<br>
77<b>DB_LOCK_DEADLOCK</b><ul compact><li>A transactional database environment operation was selected to resolve
78a deadlock.</ul>
79<b>DB_LOCK_NOTGRANTED</b><ul compact><li>A Berkeley DB Concurrent Data Store database environment configured for lock timeouts was unable
80to grant a lock in the allowed time.</ul>
81<br>
82<br>
83<b>DB_REP_HANDLE_DEAD</b><ul compact><li>The database handle has been invalidated because a replication election
84unrolled a committed transaction.</ul>
85<br>
86<br>
87<b>DB_REP_LOCKOUT</b><ul compact><li>The operation was blocked by client/master synchronization.</ul>
88<br>
89<br>
90<b>EINVAL</b><ul compact><li>If the underlying database was not of type Btree; or if an
91invalid flag value or parameter was specified.</ul>
92<br>
93<hr size=1 noshade>
94<br><b>Class</b>
95<a href="../api_c/db_class.html">DB</a>
96<br><b>See Also</b>
97<a href="../api_c/db_list.html">Databases and Related Methods</a>
98</tt>
99<table width="100%"><tr><td><br></td><td align=right>
100<a href="../api_c/api_core.html"><img src="../images/api.gif" alt="API"></a><a href="../ref/toc.html"><img src="../images/ref.gif" alt="Ref"></a>
101</td></tr></table>
102<p><font size=1>Copyright (c) 1996,2008 Oracle.  All rights reserved.</font>
103</body>
104</html>
105