1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
|
<?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 xmlns="" class="navheader">
<div class="libver">
<p>Library Version 12.1.6.1</p>
</div>
<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.h>
int
DB->join(DB *primary,
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="DBcursor->get()">DBcursor->get()</a> and
<a class="xref" href="dbcclose.html" title="DBcursor->close()">DBcursor->close()</a> cursor functions:
</p>
<div class="itemizedlist">
<ul type="disc">
<li>
<p>
<span class="bold"><strong> <a class="xref" href="dbcget.html" title="DBcursor->get()">DBcursor->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="DBcursor->close()">DBcursor->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 returns a non-zero error value on failure and 0 on success.
</span>
</span>
</p>
<div class="sect2" lang="en" xml:lang="en">
<div class="titlepage">
<div>
<div>
<h3 class="title"><a id="idm4313328"></a>Parameters</h3>
</div>
</div>
</div>
<div class="sect3" lang="en" xml:lang="en">
<div class="titlepage">
<div>
<div>
<h4 class="title"><a id="idm7215792"></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="DBcursor->get()">DBcursor->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="idm1363552"></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="idm8239800"></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="idm5501784"></a>Errors</h3>
</div>
</div>
</div>
<p>
The <code class="methodname">DB->join()</code> <span>
<span>
method may fail and 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="idm1709880"></a> 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
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="idm7515360"></a>DB_REP_LOCKOUT</h4>
</div>
</div>
</div>
<p>
The operation was blocked by client/master synchronization.
</p>
</div>
<div class="sect3" lang="en" xml:lang="en">
<div class="titlepage">
<div>
<div>
<h4 class="title"><a id="idm7816904"></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="idm4300800"></a>EINVAL</h4>
</div>
</div>
</div>
<p>
If cursor methods other than <a class="xref" href="dbcget.html" title="DBcursor->get()">DBcursor->get()</a>
or <a class="xref" href="dbcclose.html" title="DBcursor->close()">DBcursor->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="idm4537168"></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="idm882008"></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>
|