1<!--$Id: db_set_bt_prefix.so,v 10.48 2004/08/13 03:38:56 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->set_bt_prefix</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->set_bt_prefix</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 <db.h> 23<p> 24int 25DB->set_bt_prefix(DB *db, 26 size_t (*bt_prefix_fcn)(DB *, const DBT *, const DBT *)); 27</pre></b> 28<hr size=1 noshade> 29<b>Description: DB->set_bt_prefix</b> 30<p>Set the Btree prefix function. The prefix function is used to determine 31the amount by which keys stored on the Btree internal pages can be 32safely truncated without losing their uniqueness. See the 33<a href="../ref/am_conf/bt_prefix.html">Btree prefix comparison</a> section 34of the Berkeley DB Reference Guide for more details about how this works. The 35usefulness of this is data-dependent, but can produce significantly 36reduced tree sizes and search times in some data sets.</p> 37<p>If no prefix function or key comparison function is specified by the 38application, a default lexical comparison function is used as the prefix 39function. If no prefix function is specified and a key comparison 40function is specified, no prefix function is used. It is an error to 41specify a prefix function without also specifying a Btree key comparison 42function.</p> 43<p>The DB->set_bt_prefix method configures operations performed using the specified 44<a href="../api_c/db_class.html">DB</a> handle, not all operations performed on the underlying 45database.</p> 46<p>The DB->set_bt_prefix method may not be called after the <a href="../api_c/db_open.html">DB->open</a> method is called. 47If the database already exists when 48<a href="../api_c/db_open.html">DB->open</a> is called, the information specified to DB->set_bt_prefix must 49be the same as that historically used to create the database or 50corruption can occur.</p> 51<p>The DB->set_bt_prefix method 52returns a non-zero error value on failure 53and 0 on success. 54</p> 55<b>Parameters</b> <br> 56 <b>bt_prefix_fcn</b><ul compact><li>The <b>bt_prefix_fcn</b> function is the application-specific Btree 57prefix function. The prefix function takes three parameters: 58<br> 59<b><b>db</b></b><ul compact><li>The <b>db</b> parameter is the enclosing database handle.</ul> 60<b><b>dbt1</b></b><ul compact><li>The <b>dbt1</b> parameter is a <a href="../api_c/dbt_class.html">DBT</a> representing a database key.</ul> 61<b><b>dbt2</b></b><ul compact><li>The <b>dbt2</b> parameter is a <a href="../api_c/dbt_class.html">DBT</a> representing a database key.</ul> 62<br> 63<p>The <b>bt_prefix_fcn</b> function must return the number of bytes of 64the second key parameter that would be required by the Btree key 65comparison function to determine the second key parameter's ordering 66relationship with respect to the first key parameter. If the two keys 67are equal, the key length should be returned. The prefix function must 68correctly handle any key values used by the application (possibly 69including zero-length keys). The <b>data</b> and <b>size</b> fields 70of the <a href="../api_c/dbt_class.html">DBT</a> are the only fields that may be used for the purposes 71of this determination, and no particular alignment of the memory to 72which the <b>data</b> field refers may be assumed.</p></ul> 73<br> 74<br><b>Errors</b> 75<p>The DB->set_bt_prefix method 76may fail and return one of the following non-zero errors:</p> 77<br> 78<b>EINVAL</b><ul compact><li>If the method was called after <a href="../api_c/db_open.html">DB->open</a> was called; or if an 79invalid flag value or parameter was specified.</ul> 80<br> 81<hr size=1 noshade> 82<br><b>Class</b> 83<a href="../api_c/db_class.html">DB</a> 84<br><b>See Also</b> 85<a href="../api_c/db_list.html">Databases and Related Methods</a> 86</tt> 87<table width="100%"><tr><td><br></td><td align=right> 88<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> 89</td></tr></table> 90<p><font size=1>Copyright (c) 1996,2008 Oracle. All rights reserved.</font> 91</body> 92</html> 93