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