| 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::join()</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="dbget_type.html" title="Db::get_type()" /> |
| 12 | <link rel="next" href="dbkey_range.html" title="Db::key_range()" /> |
| 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::join()</th> |
| 22 | </tr> |
| 23 | <tr> |
| 24 | <td width="20%" align="left"><a accesskey="p" href="dbget_type.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="dbkey_range.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="dbjoin"></a>Db::join()</h2> |
| 38 | </div> |
| 39 | </div> |
| 40 | </div> |
| 41 | <pre class="programlisting">#include <db_cxx.h> |
| 42 | |
| 43 | int |
| 44 | Db::join(Dbc **curslist, Dbc **dbcp, u_int32_t flags);</pre> |
| 45 | <p> |
| 46 | The <code class="methodname">Db::join()</code> method creates a specialized join cursor for use in |
| 47 | performing equality or natural joins on secondary indices. For |
| 48 | information on how to organize your data to use this functionality, |
| 49 | see <a href="../../programmer_reference/am_cursor.html#am_join" class="olink">Equality join</a>. |
| 50 | </p> |
| 51 | <p> |
| 52 | The <code class="methodname">Db::join()</code> method is called using the |
| 53 | <a class="link" href="db.html" title="Chapter 2. The Db Handle">Db</a> handle of the primary |
| 54 | database. |
| 55 | </p> |
| 56 | <p> |
| 57 | The join cursor supports only the <a class="xref" href="dbcget.html" title="Dbc::get()">Dbc::get()</a> and |
| 58 | <a class="xref" href="dbcclose.html" title="Dbc::close()">Dbc::close()</a> cursor functions: |
| 59 | </p> |
| 60 | <div class="itemizedlist"> |
| 61 | <ul type="disc"> |
| 62 | <li> |
| 63 | <p> |
| 64 | <span class="bold"><strong> <a class="xref" href="dbcget.html" title="Dbc::get()">Dbc::get()</a> </strong></span> |
| 65 | </p> |
| 66 | <p> |
| 67 | Iterates over the values associated with the keys to which each item |
| 68 | in <span class="bold"><strong>curslist</strong></span> was initialized. Any |
| 69 | data value that appears in all items specified by the <span class="bold"><strong>curslist</strong></span> parameter is then used as a key into |
| 70 | the <span class="bold"><strong>primary</strong></span>, and the key/data pair |
| 71 | found in the <span class="bold"><strong>primary</strong></span> is returned. The |
| 72 | <span class="bold"><strong>flags</strong></span> parameter must be set to 0 or |
| 73 | the following value: |
| 74 | |
| 75 | </p> |
| 76 | <div class="itemizedlist"> |
| 77 | <ul type="circle"> |
| 78 | <li> |
| 79 | <p> |
| 80 | <span class="bold"><strong><code class="literal">DB_JOIN_ITEM</code></strong></span> |
| 81 | </p> |
| 82 | <p> |
| 83 | Do not use the data value found in all the cursors as a lookup key for |
| 84 | the <span class="bold"><strong>primary</strong></span>, but simply return it in |
| 85 | the key parameter instead. The data parameter is left unchanged. |
| 86 | </p> |
| 87 | </li> |
| 88 | </ul> |
| 89 | </div> |
| 90 | <p> |
| 91 | In addition, the following flag may be set by bitwise inclusively |
| 92 | <span class="bold"><strong>OR</strong></span>'ing it into the <span class="bold"><strong>flags</strong></span> parameter: |
| 93 | </p> |
| 94 | <div class="itemizedlist"> |
| 95 | <ul type="circle"> |
| 96 | <li> |
| 97 | <p> |
| 98 | <span class="bold"><strong> <code class="literal">DB_READ_UNCOMMITTED</code></strong></span> |
| 99 | </p> |
| 100 | <p> |
| 101 | Configure a transactional join operation to have degree 1 isolation, |
| 102 | reading modified but not yet committed data. Silently ignored if the |
| 103 | <a class="link" href="dbopen.html#dbopen_DB_READ_UNCOMMITTED">DB_READ_UNCOMMITTED</a> |
| 104 | flag was not specified when the underlying database was opened. |
| 105 | </p> |
| 106 | </li> |
| 107 | <li> |
| 108 | <p> |
| 109 | <span class="bold"><strong><code class="literal">DB_RMW</code></strong></span> |
| 110 | </p> |
| 111 | <p> |
| 112 | Acquire write locks instead of read locks when doing the read, if |
| 113 | locking is configured. Setting this flag can eliminate deadlock |
| 114 | during a read-modify-write cycle by acquiring the write lock during |
| 115 | the read part of the cycle so that another thread of control acquiring |
| 116 | a read lock for the same item, in its own read-modify-write cycle, |
| 117 | will not result in deadlock. |
| 118 | </p> |
| 119 | </li> |
| 120 | </ul> |
| 121 | </div> |
| 122 | </li> |
| 123 | <li> |
| 124 | <p> |
| 125 | <span class="bold"><strong> <a class="xref" href="dbcclose.html" title="Dbc::close()">Dbc::close()</a> </strong></span> |
| 126 | </p> |
| 127 | <p> |
| 128 | Close the returned cursor and release all resources. (Closing the |
| 129 | cursors in <span class="bold"><strong>curslist</strong></span> is the |
| 130 | responsibility of the caller.) |
| 131 | </p> |
| 132 | </li> |
| 133 | </ul> |
| 134 | </div> |
| 135 | <p> |
| 136 | The <code class="methodname">Db::join()</code> <span> |
| 137 | |
| 138 | <span> |
| 139 | method either returns a non-zero error value or throws an |
| 140 | exception that encapsulates a non-zero error value on |
| 141 | failure, and returns 0 on success. |
| 142 | </span> |
| 143 | </span> |
| 144 | </p> |
| 145 | <div class="sect2" lang="en" xml:lang="en"> |
| 146 | <div class="titlepage"> |
| 147 | <div> |
| 148 | <div> |
| 149 | <h3 class="title"><a id="idp70408"></a>Parameters</h3> |
| 150 | </div> |
| 151 | </div> |
| 152 | </div> |
| 153 | <div class="sect3" lang="en" xml:lang="en"> |
| 154 | <div class="titlepage"> |
| 155 | <div> |
| 156 | <div> |
| 157 | <h4 class="title"><a id="idp840904"></a>curslist</h4> |
| 158 | </div> |
| 159 | </div> |
| 160 | </div> |
| 161 | <p> |
| 162 | The <span class="bold"><strong>curslist</strong></span> parameter contains a |
| 163 | NULL terminated array of cursors. Each cursor must have been |
| 164 | initialized to refer to the key on which the underlying database |
| 165 | should be joined. Typically, this initialization is done by a |
| 166 | <a class="xref" href="dbcget.html" title="Dbc::get()">Dbc::get()</a> call with the |
| 167 | <a class="link" href="dbcget.html#dbcget_DB_SET">DB_SET</a> flag |
| 168 | specified. Once the cursors have been passed as part of a <span class="bold"><strong>curslist</strong></span>, they should not be accessed or |
| 169 | modified until the newly created join cursor has been closed, or else |
| 170 | inconsistent results may be returned. |
| 171 | </p> |
| 172 | <p> |
| 173 | Joined values are retrieved by doing a sequential iteration over the |
| 174 | first cursor in the <span class="bold"><strong>curslist</strong></span> |
| 175 | parameter, and a nested iteration over each secondary cursor in the |
| 176 | order they are specified in the <span class="bold"><strong>curslist</strong></span> parameter. This requires database |
| 177 | traversals to search for the current datum in all the cursors after |
| 178 | the first. For this reason, the best join performance normally |
| 179 | results from sorting the cursors from the one that refers to the least |
| 180 | number of data items to the one that refers to the most. By default, |
| 181 | <code class="methodname">Db::join()</code> does this sort on behalf of its caller. |
| 182 | </p> |
| 183 | <p> |
| 184 | For the returned join cursor to be used in a transaction-protected |
| 185 | manner, the cursors listed in <span class="bold"><strong>curslist</strong></span> must have been created within the |
| 186 | context of the same transaction. |
| 187 | </p> |
| 188 | </div> |
| 189 | <div class="sect3" lang="en" xml:lang="en"> |
| 190 | <div class="titlepage"> |
| 191 | <div> |
| 192 | <div> |
| 193 | <h4 class="title"><a id="idm1885232"></a>dbcp</h4> |
| 194 | </div> |
| 195 | </div> |
| 196 | </div> |
| 197 | <p> |
| 198 | The newly created join cursor is returned in the memory location to |
| 199 | which <span class="bold"><strong>dbcp</strong></span> refers. |
| 200 | </p> |
| 201 | </div> |
| 202 | <div class="sect3" lang="en" xml:lang="en"> |
| 203 | <div class="titlepage"> |
| 204 | <div> |
| 205 | <div> |
| 206 | <h4 class="title"><a id="idp3889000"></a>flags</h4> |
| 207 | </div> |
| 208 | </div> |
| 209 | </div> |
| 210 | <p> |
| 211 | The <span class="bold"><strong>flags</strong></span> parameter must be set to 0 |
| 212 | or the following value: |
| 213 | </p> |
| 214 | <div class="itemizedlist"> |
| 215 | <ul type="disc"> |
| 216 | <li> |
| 217 | <p><a id="join_DB_JOIN_NOSORT"></a> |
| 218 | <code class="literal">DB_JOIN_NOSORT</code> |
| 219 | </p> |
| 220 | <p> |
| 221 | Do not sort the cursors based on the number of data items to which |
| 222 | they refer. If the data are structured so that cursors with many data |
| 223 | items also share many common elements, higher performance will result |
| 224 | from listing those cursors before cursors with fewer data items; that |
| 225 | is, a sort order other than the default. The DB_JOIN_NOSORT flag |
| 226 | permits applications to perform join optimization prior to calling the |
| 227 | <code class="methodname">Db::join()</code> method. |
| 228 | </p> |
| 229 | </li> |
| 230 | </ul> |
| 231 | </div> |
| 232 | </div> |
| 233 | </div> |
| 234 | <div class="sect2" lang="en" xml:lang="en"> |
| 235 | <div class="titlepage"> |
| 236 | <div> |
| 237 | <div> |
| 238 | <h3 class="title"><a id="idp1018528"></a>Errors</h3> |
| 239 | </div> |
| 240 | </div> |
| 241 | </div> |
| 242 | <p> |
| 243 | The <code class="methodname">Db::join()</code> <span> |
| 244 | |
| 245 | <span> |
| 246 | method may fail and throw a <a class="link" href="dbexception.html" title="Chapter 6. The DbException Class">DbException</a> |
| 247 | exception, encapsulating one of the following non-zero errors, or return one |
| 248 | of the following non-zero errors: |
| 249 | </span> |
| 250 | </span> |
| 251 | </p> |
| 252 | <div class="sect3" lang="en" xml:lang="en"> |
| 253 | <div class="titlepage"> |
| 254 | <div> |
| 255 | <div> |
| 256 | <h4 class="title"><a id="idp623488"></a> <span>DbRepHandleDeadException or</span> DB_REP_HANDLE_DEAD</h4> |
| 257 | </div> |
| 258 | </div> |
| 259 | </div> |
| 260 | <p> |
| 261 | When a client synchronizes with the master, it is possible for committed |
| 262 | transactions to be rolled back. This invalidates all the database and cursor |
| 263 | handles opened in the replication environment. Once this occurs, an attempt to use |
| 264 | such a handle will |
| 265 | <span> |
| 266 | throw a <a class="xref" href="dbrephandledead.html" title="DbRepHandleDeadException">DbRepHandleDeadException</a> (if |
| 267 | your application is configured to throw exceptions), or |
| 268 | </span> |
| 269 | return <code class="literal">DB_REP_HANDLE_DEAD</code>. |
| 270 | The application will need to discard the handle and open a new one in order to |
| 271 | continue processing. |
| 272 | </p> |
| 273 | </div> |
| 274 | <div class="sect3" lang="en" xml:lang="en"> |
| 275 | <div class="titlepage"> |
| 276 | <div> |
| 277 | <div> |
| 278 | <h4 class="title"><a id="idm1810408"></a><span>DbDeadlockException or </span>DB_REP_LOCKOUT</h4> |
| 279 | </div> |
| 280 | </div> |
| 281 | </div> |
| 282 | <p> |
| 283 | The operation was blocked by client/master synchronization. |
| 284 | </p> |
| 285 | <p> |
| 286 | <a class="xref" href="dbdeadlock.html" title="DbDeadlockException">DbDeadlockException</a> is thrown if |
| 287 | your Berkeley DB API is configured to throw exceptions. |
| 288 | Otherwise, <code class="literal">DB_REP_LOCKOUT</code> is returned. |
| 289 | </p> |
| 290 | </div> |
| 291 | <div class="sect3" lang="en" xml:lang="en"> |
| 292 | <div class="titlepage"> |
| 293 | <div> |
| 294 | <div> |
| 295 | <h4 class="title"><a id="idm586808"></a>DB_SECONDARY_BAD</h4> |
| 296 | </div> |
| 297 | </div> |
| 298 | </div> |
| 299 | <p> |
| 300 | A secondary index references a nonexistent primary key. |
| 301 | </p> |
| 302 | </div> |
| 303 | <div class="sect3" lang="en" xml:lang="en"> |
| 304 | <div class="titlepage"> |
| 305 | <div> |
| 306 | <div> |
| 307 | <h4 class="title"><a id="idp2089648"></a>EINVAL</h4> |
| 308 | </div> |
| 309 | </div> |
| 310 | </div> |
| 311 | <p> |
| 312 | If cursor methods other than <a class="xref" href="dbcget.html" title="Dbc::get()">Dbc::get()</a> |
| 313 | or <a class="xref" href="dbcclose.html" title="Dbc::close()">Dbc::close()</a> were called; |
| 314 | or if an invalid flag value or parameter was specified. |
| 315 | </p> |
| 316 | </div> |
| 317 | </div> |
| 318 | <div class="sect2" lang="en" xml:lang="en"> |
| 319 | <div class="titlepage"> |
| 320 | <div> |
| 321 | <div> |
| 322 | <h3 class="title"><a id="idp3993464"></a>Class</h3> |
| 323 | </div> |
| 324 | </div> |
| 325 | </div> |
| 326 | <p> |
| 327 | <a class="link" href="db.html" title="Chapter 2. The Db Handle">Db</a> |
| 328 | </p> |
| 329 | </div> |
| 330 | <div class="sect2" lang="en" xml:lang="en"> |
| 331 | <div class="titlepage"> |
| 332 | <div> |
| 333 | <div> |
| 334 | <h3 class="title"><a id="idm2181688"></a>See Also</h3> |
| 335 | </div> |
| 336 | </div> |
| 337 | </div> |
| 338 | <p> |
| 339 | <a class="xref" href="db.html#dblist" title="Database and Related Methods">Database and Related Methods</a> |
| 340 | </p> |
| 341 | </div> |
| 342 | </div> |
| 343 | <div class="navfooter"> |
| 344 | <hr /> |
| 345 | <table width="100%" summary="Navigation footer"> |
| 346 | <tr> |
| 347 | <td width="40%" align="left"><a accesskey="p" href="dbget_type.html">Prev</a> </td> |
| 348 | <td width="20%" align="center"> |
| 349 | <a accesskey="u" href="db.html">Up</a> |
| 350 | </td> |
| 351 | <td width="40%" align="right"> <a accesskey="n" href="dbkey_range.html">Next</a></td> |
| 352 | </tr> |
| 353 | <tr> |
| 354 | <td width="40%" align="left" valign="top">Db::get_type() </td> |
| 355 | <td width="20%" align="center"> |
| 356 | <a accesskey="h" href="index.html">Home</a> |
| 357 | </td> |
| 358 | <td width="40%" align="right" valign="top"> Db::key_range()</td> |
| 359 | </tr> |
| 360 | </table> |
| 361 | </div> |
| 362 | </body> |
| 363 | </html> |