1<!--$Id: db_join.so,v 10.60 2007/10/24 16:06:06 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::join</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::join</b> 14</td> 15<td align=right> 16<a href="/api_cxx/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_cxx.h> 23<p> 24int 25Db::join(Dbc **curslist, Dbc **dbcp, u_int32_t flags); 26</pre></b> 27<hr size=1 noshade> 28<b>Description: Db::join</b> 29<p>The Db::join method creates a specialized join cursor for use in 30performing equality or natural joins on secondary indices. For 31information on how to organize your data to use this functionality, see 32<a href="/ref/am/join.html">Equality join</a>.</p> 33<p>The Db::join method method is called using the <a href="/api_cxx/db_class.html">Db</a> handle of 34the primary database.</p> 35<p>The join cursor supports only the <a href="/api_cxx/dbc_get.html">Dbc::get</a> and <b>dbc_close</b> 36cursor functions:</p> 37<br> 38<b><a href="/api_cxx/dbc_get.html">Dbc::get</a></b><ul compact><li>Iterates over the values associated with the keys to which each item in 39<b>curslist</b> was initialized. Any data value that appears in all 40items specified by the <b>curslist</b> parameter is then used as a key 41into the <b>primary</b>, and the key/data pair found in the 42<b>primary</b> is returned. 43The <b>flags</b> parameter must be set to 0 or 44the following value: 45<br> 46<b><a name="DB_JOIN_ITEM">DB_JOIN_ITEM</a></b><ul compact><li>Do not use the data value found in all the cursors as a lookup key for 47the <b>primary</b>, but simply return it in the key parameter instead. 48The data parameter is left unchanged.</ul> 49<br> 50In addition, the following flag may be set by 51bitwise inclusively <b>OR</b>'ing it into the <b>flags</b> parameter: 52<br> 53<b><a name="DB_READ_UNCOMMITTED">DB_READ_UNCOMMITTED</a></b><ul compact><li>Configure a transactional join operation to have degree 1 isolation, 54reading modified but not yet committed data. Silently ignored if the 55<a href="/api_cxx/db_open.html#DB_READ_UNCOMMITTED">DB_READ_UNCOMMITTED</a> flag was not specified when the underlying 56database was opened.</ul> 57<b><a name="DB_RMW">DB_RMW</a></b><ul compact><li>Acquire write locks instead of read locks when doing the read, if 58locking is configured. Setting this flag can eliminate deadlock during 59a read-modify-write cycle by acquiring the write lock during the read 60part of the cycle so that another thread of control acquiring a read 61lock for the same item, in its own read-modify-write cycle, will not 62result in deadlock. 63</ul> 64<br></ul> 65<b><a href="/api_cxx/dbc_close.html">Dbc::close</a></b><ul compact><li>Close the returned cursor and release all resources. (Closing the cursors 66in <b>curslist</b> is the responsibility of the caller.)</ul> 67<br> 68<p>The Db::join method 69either returns a non-zero error value 70or throws an exception that encapsulates a non-zero error value on 71failure, and returns 0 on success. 72</p> 73<b>Parameters</b> <br> 74 <b>curslist</b><ul compact><li>The <b>curslist</b> parameter contains a NULL terminated array of cursors. 75Each cursor must have been initialized to refer to the key on which the 76underlying database should be joined. Typically, this initialization is done 77by a <a href="/api_cxx/dbc_get.html">Dbc::get</a> call with the <a href="/api_cxx/dbc_get.html#DB_SET">DB_SET</a> flag specified. Once the 78cursors have been passed as part of a <b>curslist</b>, they should not 79be accessed or modified until the newly created join cursor has been closed, 80or else inconsistent results may be returned. 81<p>Joined values are retrieved by doing a sequential iteration over the first 82cursor in the <b>curslist</b> parameter, and a nested iteration over each 83secondary cursor in the order they are specified in the <b>curslist</b> 84parameter. This requires database traversals to search for the current 85datum in all the cursors after the first. For this reason, the best join 86performance normally results from sorting the cursors from the one that 87refers to the least number of data items to the one that refers to the 88most. By default, Db::join does this sort on behalf of its caller.</p> 89<p>For the returned join cursor to be used in a transaction-protected manner, 90the cursors listed in <b>curslist</b> must have been created within the 91context of the same transaction.</p></ul> 92 <b>dbcp</b><ul compact><li>The newly created join cursor is returned in the memory location to 93which <b>dbcp</b> refers.</ul> 94 <b>flags</b><ul compact><li>The <b>flags</b> parameter must be set to 0 or 95the following value: 96<br> 97<b><a name="DB_JOIN_NOSORT">DB_JOIN_NOSORT</a></b><ul compact><li>Do not sort the cursors based on the number of data items to which they 98refer. If the data are structured so that cursors with many data items 99also share many common elements, higher performance will result from 100listing those cursors before cursors with fewer data items; that is, a 101sort order other than the default. The DB_JOIN_NOSORT flag 102permits applications to perform join optimization prior to calling 103Db::join.</ul> 104<br></ul> 105<br> 106<br><b>Errors</b> 107<p>The Db::join method 108may fail and throw 109<a href="/api_cxx/except_class.html">DbException</a>, 110encapsulating one of the following non-zero errors, or return one of 111the following non-zero errors:</p> 112<br> 113<b>DB_REP_HANDLE_DEAD</b><ul compact><li>The database handle has been invalidated because a replication election 114unrolled a committed transaction.</ul> 115<br> 116<br> 117<b>DB_REP_LOCKOUT</b><ul compact><li>The operation was blocked by client/master synchronization.</ul> 118<br> 119<br> 120<b>DB_SECONDARY_BAD</b><ul compact><li>A secondary index references a nonexistent primary key.</ul> 121<br> 122<br> 123<b>EINVAL</b><ul compact><li>If cursor methods other than <a href="/api_cxx/dbc_get.html">Dbc::get</a> or <a href="/api_cxx/dbc_close.html">Dbc::close</a> were 124called; or if an 125invalid flag value or parameter was specified.</ul> 126<br> 127<hr size=1 noshade> 128<br><b>Class</b> 129<a href="/api_cxx/db_class.html">Db</a> 130<br><b>See Also</b> 131<a href="/api_cxx/db_list.html">Databases and Related Methods</a> 132</tt> 133<table width="100%"><tr><td><br></td><td align=right> 134<a href="/api_cxx/api_core.html"><img src="/images/api.gif" alt="API"></a><a href="/ref/toc.html"><img src="/images/ref.gif" alt="Ref"></a> 135</td></tr></table> 136<p><font size=1>Copyright (c) 1996,2008 Oracle. All rights reserved.</font> 137</body> 138</html> 139