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>DB->set_partition()</title> 7 <link rel="stylesheet" href="apiReference.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 C API Reference" /> 10 <link rel="up" href="db.html" title="Chapter��2.�� The DB Handle" /> 11 <link rel="prev" href="dbset_pagesize.html" title="DB->set_pagesize()" /> 12 <link rel="next" href="dbset_partition_dirs.html" title="DB->set_partition_dirs()" /> 13 </head> 14 <body> 15 <div class="navheader"> 16 <table width="100%" summary="Navigation header"> 17 <tr> 18 <th colspan="3" align="center">DB->set_partition()</th> 19 </tr> 20 <tr> 21 <td width="20%" align="left"><a accesskey="p" href="dbset_pagesize.html">Prev</a>��</td> 22 <th width="60%" align="center">Chapter��2.�� 23 The DB Handle 24 </th> 25 <td width="20%" align="right">��<a accesskey="n" href="dbset_partition_dirs.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="dbset_partition"></a>DB->set_partition()</h2> 35 </div> 36 </div> 37 </div> 38 <pre class="programlisting">#include <db.h> 39 40int 41DB->set_partition(DB * db, u_int32_t parts, DBT *keys, 42 u_int32_t (*db_partition_fcn) (DB *db, DBT *key)); </pre> 43 <p> 44 Set up partitioning for a database. Partitioning may be used on either BTREE or HASH databases. 45 Partitions may be specified by either a set of keys specifying a range of values in each partition 46 or with a callback function that returns the number of the partition to put a specific key. 47 Partition range keys may only be specified for BTREE databases. 48 </p> 49 <p> 50 Partitions are implimented as separate database files and can help reduce contention within a logical 51 database. Contention can come from multiple threads of control accessing database pages simultaniously. 52 Typically these pages are the root of a btree and the metadata page which contains allocation information 53 in both BTREE and HASH databases. Each partition has its own metadata and root pages. 54 </p> 55 <div class="sect2" lang="en" xml:lang="en"> 56 <div class="titlepage"> 57 <div> 58 <div> 59 <h3 class="title"><a id="id1648846"></a>Parameters</h3> 60 </div> 61 </div> 62 </div> 63 <p> 64 Exactly one of the parameters 65 <span class="bold"><strong>keys</strong></span> and 66 <span class="bold"><strong>partition_fcn</strong></span> must be NULL. 67 </p> 68 <div class="sect3" lang="en" xml:lang="en"> 69 <div class="titlepage"> 70 <div> 71 <div> 72 <h4 class="title"><a id="id1648972"></a>parts</h4> 73 </div> 74 </div> 75 </div> 76 <p> 77 The <span class="bold"><strong>parts</strong></span> parameter is the number of partitions to create. 78 The value must be 2 or greater. 79 </p> 80 </div> 81 <div class="sect3" lang="en" xml:lang="en"> 82 <div class="titlepage"> 83 <div> 84 <div> 85 <h4 class="title"><a id="id1649162"></a>keys</h4> 86 </div> 87 </div> 88 </div> 89 <p> 90 The <span class="bold"><strong>keys</strong></span> parameter is an 91 array of DBT structures containing the keys that specify 92 the range of key values to be stored in each partition. 93 Each key specifies the minimum value that may be stored in 94 the corresponding partition. The number of keys must be 95 one less than the number of partitions specified by the 96 <span class="bold"><strong>parts</strong></span> parameter since the 97 first partition will hold any key less than the first key 98 in the array. 99 </p> 100 </div> 101 <div class="sect3" lang="en" xml:lang="en"> 102 <div class="titlepage"> 103 <div> 104 <div> 105 <h4 class="title"><a id="id1649019"></a>db_partition_fcn</h4> 106 </div> 107 </div> 108 </div> 109 <p> 110 The <span class="bold"><strong>db_partition_fcn</strong></span> 111 parameter is the application-specified partitioning 112 function. The function returns an integer which will be 113 used modulo the number of partitions specified by the 114 <span class="bold"><strong>parts</strong></span> parameter. 115 The function will be called with two parameters: 116 </p> 117 <div class="itemizedlist"> 118 <ul type="disc"> 119 <li> 120 <p> 121 <code class="literal">db</code> 122 </p> 123 <p> 124 The <span class="bold"><strong>db</strong></span> parameter is the database handle. 125 </p> 126 </li> 127 <li> 128 <p> 129 <code class="literal">key</code> 130 </p> 131 <p> 132 The <span class="bold"><strong>key</strong></span> parameter 133 is the key for which a partition number should be 134 returned. 135 </p> 136 </li> 137 </ul> 138 </div> 139 </div> 140 </div> 141 <div class="sect2" lang="en" xml:lang="en"> 142 <div class="titlepage"> 143 <div> 144 <div> 145 <h3 class="title"><a id="id1648897"></a>Class</h3> 146 </div> 147 </div> 148 </div> 149 <p> 150 <a class="link" href="db.html" title="Chapter��2.�� The DB Handle">DB</a> 151 </p> 152 </div> 153 <div class="sect2" lang="en" xml:lang="en"> 154 <div class="titlepage"> 155 <div> 156 <div> 157 <h3 class="title"><a id="id1649066"></a>See Also</h3> 158 </div> 159 </div> 160 </div> 161 <p> 162 <a class="xref" href="db.html#dblist" title="Database and Related Methods">Database and Related Methods</a> 163 </p> 164 </div> 165 </div> 166 <div class="navfooter"> 167 <hr /> 168 <table width="100%" summary="Navigation footer"> 169 <tr> 170 <td width="40%" align="left"><a accesskey="p" href="dbset_pagesize.html">Prev</a>��</td> 171 <td width="20%" align="center"> 172 <a accesskey="u" href="db.html">Up</a> 173 </td> 174 <td width="40%" align="right">��<a accesskey="n" href="dbset_partition_dirs.html">Next</a></td> 175 </tr> 176 <tr> 177 <td width="40%" align="left" valign="top">DB->set_pagesize()��</td> 178 <td width="20%" align="center"> 179 <a accesskey="h" href="index.html">Home</a> 180 </td> 181 <td width="40%" align="right" valign="top">��DB->set_partition_dirs()</td> 182 </tr> 183 </table> 184 </div> 185 </body> 186</html> 187