<?xml version="1.0" encoding="UTF-8" standalone="no"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Db::join()</title> <link rel="stylesheet" href="apiReference.css" type="text/css" /> <meta name="generator" content="DocBook XSL Stylesheets V1.73.2" /> <link rel="start" href="index.html" title="Berkeley DB C++ API Reference" /> <link rel="up" href="db.html" title="Chapter 2. The Db Handle" /> <link rel="prev" href="dbget_type.html" title="Db::get_type()" /> <link rel="next" href="dbkey_range.html" title="Db::key_range()" /> </head> <body> <div class="navheader"> <table width="100%" summary="Navigation header"> <tr> <th colspan="3" align="center">Db::join()</th> </tr> <tr> <td width="20%" align="left"><a accesskey="p" href="dbget_type.html">Prev</a> </td> <th width="60%" align="center">Chapter 2. The Db Handle </th> <td width="20%" align="right"> <a accesskey="n" href="dbkey_range.html">Next</a></td> </tr> </table> <hr /> </div> <div class="sect1" lang="en" xml:lang="en"> <div class="titlepage"> <div> <div> <h2 class="title" style="clear: both"><a id="dbjoin"></a>Db::join()</h2> </div> </div> </div> <pre class="programlisting">#include <db_cxx.h> int Db::join(Dbc **curslist, Dbc **dbcp, u_int32_t flags);</pre> <p> The <code class="methodname">Db::join()</code> method creates a specialized join cursor for use in performing equality or natural joins on secondary indices. For information on how to organize your data to use this functionality, see <a href="../../programmer_reference/am_cursor.html#am_join" class="olink">Equality join</a>. </p> <p> The <code class="methodname">Db::join()</code> method is called using the <a class="link" href="db.html" title="Chapter 2. The Db Handle">Db</a> handle of the primary database. </p> <p> The join cursor supports only the <a class="xref" href="dbcget.html" title="Dbc::get()">Dbc::get()</a> and <a class="xref" href="dbcclose.html" title="Dbc::close()">Dbc::close()</a> cursor functions: </p> <div class="itemizedlist"> <ul type="disc"> <li> <p> <span class="bold"><strong> <a class="xref" href="dbcget.html" title="Dbc::get()">Dbc::get()</a> </strong></span> </p> <p> Iterates over the values associated with the keys to which each item in <span class="bold"><strong>curslist</strong></span> was initialized. Any 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 the <span class="bold"><strong>primary</strong></span>, and the key/data pair found in the <span class="bold"><strong>primary</strong></span> is returned. The <span class="bold"><strong>flags</strong></span> parameter must be set to 0 or the following value: </p> <div class="itemizedlist"> <ul type="circle"> <li> <p> <span class="bold"><strong><code class="literal">DB_JOIN_ITEM</code></strong></span> </p> <p> Do not use the data value found in all the cursors as a lookup key for the <span class="bold"><strong>primary</strong></span>, but simply return it in the key parameter instead. The data parameter is left unchanged. </p> </li> </ul> </div> <p> In addition, the following flag may be set by bitwise inclusively <span class="bold"><strong>OR</strong></span>'ing it into the <span class="bold"><strong>flags</strong></span> parameter: </p> <div class="itemizedlist"> <ul type="circle"> <li> <p> <span class="bold"><strong> <code class="literal">DB_READ_UNCOMMITTED</code></strong></span> </p> <p> Configure a transactional join operation to have degree 1 isolation, reading modified but not yet committed data. Silently ignored if the <a class="link" href="dbopen.html#dbopen_DB_READ_UNCOMMITTED">DB_READ_UNCOMMITTED</a> flag was not specified when the underlying database was opened. </p> </li> <li> <p> <span class="bold"><strong><code class="literal">DB_RMW</code></strong></span> </p> <p> Acquire write locks instead of read locks when doing the read, if locking is configured. Setting this flag can eliminate deadlock during a read-modify-write cycle by acquiring the write lock during the read part of the cycle so that another thread of control acquiring a read lock for the same item, in its own read-modify-write cycle, will not result in deadlock. </p> </li> </ul> </div> </li> <li> <p> <span class="bold"><strong> <a class="xref" href="dbcclose.html" title="Dbc::close()">Dbc::close()</a> </strong></span> </p> <p> Close the returned cursor and release all resources. (Closing the cursors in <span class="bold"><strong>curslist</strong></span> is the responsibility of the caller.) </p> </li> </ul> </div> <p> The <code class="methodname">Db::join()</code> <span> <span> method either returns a non-zero error value or throws an exception that encapsulates a non-zero error value on failure, and returns 0 on success. </span> </span> </p> <div class="sect2" lang="en" xml:lang="en"> <div class="titlepage"> <div> <div> <h3 class="title"><a id="id1639144"></a>Parameters</h3> </div> </div> </div> <div class="sect3" lang="en" xml:lang="en"> <div class="titlepage"> <div> <div> <h4 class="title"><a id="id1638877"></a>curslist</h4> </div> </div> </div> <p> The <span class="bold"><strong>curslist</strong></span> parameter contains a NULL terminated array of cursors. Each cursor must have been initialized to refer to the key on which the underlying database should be joined. Typically, this initialization is done by a <a class="xref" href="dbcget.html" title="Dbc::get()">Dbc::get()</a> call with the <a class="link" href="dbcget.html#dbcget_DB_SET">DB_SET</a> flag specified. Once the cursors have been passed as part of a <span class="bold"><strong>curslist</strong></span>, they should not be accessed or modified until the newly created join cursor has been closed, or else inconsistent results may be returned. </p> <p> Joined values are retrieved by doing a sequential iteration over the first cursor in the <span class="bold"><strong>curslist</strong></span> parameter, and a nested iteration over each secondary cursor in the order they are specified in the <span class="bold"><strong>curslist</strong></span> parameter. This requires database traversals to search for the current datum in all the cursors after the first. For this reason, the best join performance normally results from sorting the cursors from the one that refers to the least number of data items to the one that refers to the most. By default, <code class="methodname">Db::join()</code> does this sort on behalf of its caller. </p> <p> For the returned join cursor to be used in a transaction-protected manner, the cursors listed in <span class="bold"><strong>curslist</strong></span> must have been created within the context of the same transaction. </p> </div> <div class="sect3" lang="en" xml:lang="en"> <div class="titlepage"> <div> <div> <h4 class="title"><a id="id1638370"></a>dbcp</h4> </div> </div> </div> <p> The newly created join cursor is returned in the memory location to which <span class="bold"><strong>dbcp</strong></span> refers. </p> </div> <div class="sect3" lang="en" xml:lang="en"> <div class="titlepage"> <div> <div> <h4 class="title"><a id="id1639064"></a>flags</h4> </div> </div> </div> <p> The <span class="bold"><strong>flags</strong></span> parameter must be set to 0 or the following value: </p> <div class="itemizedlist"> <ul type="disc"> <li> <p><a id="join_DB_JOIN_NOSORT"></a> <code class="literal">DB_JOIN_NOSORT</code> </p> <p> Do not sort the cursors based on the number of data items to which they refer. If the data are structured so that cursors with many data items also share many common elements, higher performance will result from listing those cursors before cursors with fewer data items; that is, a sort order other than the default. The DB_JOIN_NOSORT flag permits applications to perform join optimization prior to calling the <code class="methodname">Db::join()</code> method. </p> </li> </ul> </div> </div> </div> <div class="sect2" lang="en" xml:lang="en"> <div class="titlepage"> <div> <div> <h3 class="title"><a id="id1638984"></a>Errors</h3> </div> </div> </div> <p> The <code class="methodname">Db::join()</code> <span> <span> method may fail and throw a <a class="link" href="dbexception.html" title="Chapter 6. The DbException Class">DbException</a> exception, encapsulating one of the following non-zero errors, or return one of the following non-zero errors: </span> </span> </p> <div class="sect3" lang="en" xml:lang="en"> <div class="titlepage"> <div> <div> <h4 class="title"><a id="id1638820"></a><span>DbRepHandleDeadException or</span> DB_REP_HANDLE_DEAD</h4> </div> </div> </div> <p> When a client synchronizes with the master, it is possible for committed transactions to be rolled back. This invalidates all the database and cursor handles opened in the replication environment. Once this occurs, an attempt to use such a handle will <span> throw a <a class="xref" href="dbrephandledead.html" title="DbRepHandleDeadException">DbRepHandleDeadException</a> (if your application is configured to throw exceptions), or </span> return <code class="literal">DB_REP_HANDLE_DEAD</code>. The application will need to discard the handle and open a new one in order to continue processing. </p> </div> <div class="sect3" lang="en" xml:lang="en"> <div class="titlepage"> <div> <div> <h4 class="title"><a id="id1639412"></a><span>DbDeadlockException or </span>DB_REP_LOCKOUT</h4> </div> </div> </div> <p> The operation was blocked by client/master synchronization. </p> <p> <a class="xref" href="dbdeadlock.html" title="DbDeadlockException">DbDeadlockException</a> is thrown if your Berkeley DB API is configured to throw exceptions. Otherwise, <code class="literal">DB_REP_LOCKOUT</code> is returned. </p> </div> <div class="sect3" lang="en" xml:lang="en"> <div class="titlepage"> <div> <div> <h4 class="title"><a id="id1639067"></a>DB_SECONDARY_BAD</h4> </div> </div> </div> <p> A secondary index references a nonexistent primary key. </p> </div> <div class="sect3" lang="en" xml:lang="en"> <div class="titlepage"> <div> <div> <h4 class="title"><a id="id1639168"></a>EINVAL</h4> </div> </div> </div> <p> If cursor methods other than <a class="xref" href="dbcget.html" title="Dbc::get()">Dbc::get()</a> or <a class="xref" href="dbcclose.html" title="Dbc::close()">Dbc::close()</a> were called; or if an invalid flag value or parameter was specified. </p> </div> </div> <div class="sect2" lang="en" xml:lang="en"> <div class="titlepage"> <div> <div> <h3 class="title"><a id="id1639111"></a>Class</h3> </div> </div> </div> <p> <a class="link" href="db.html" title="Chapter 2. The Db Handle">Db</a> </p> </div> <div class="sect2" lang="en" xml:lang="en"> <div class="titlepage"> <div> <div> <h3 class="title"><a id="id1638707"></a>See Also</h3> </div> </div> </div> <p> <a class="xref" href="db.html#dblist" title="Database and Related Methods">Database and Related Methods</a> </p> </div> </div> <div class="navfooter"> <hr /> <table width="100%" summary="Navigation footer"> <tr> <td width="40%" align="left"><a accesskey="p" href="dbget_type.html">Prev</a> </td> <td width="20%" align="center"> <a accesskey="u" href="db.html">Up</a> </td> <td width="40%" align="right"> <a accesskey="n" href="dbkey_range.html">Next</a></td> </tr> <tr> <td width="40%" align="left" valign="top">Db::get_type() </td> <td width="20%" align="center"> <a accesskey="h" href="index.html">Home</a> </td> <td width="40%" align="right" valign="top"> Db::key_range()</td> </tr> </table> </div> </body> </html>