Debian Codegraph @

docs/programmer_reference/stl_db_advanced_usage.html

raw symbols SCIP
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>Using advanced Berkeley DB features with dbstl</title>
7 <link rel="stylesheet" href="gettingStarted.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 Programmer's Reference Guide" />
10 <link rel="up" href="stl.html" title="Chapter 7. Standard Template Library API" />
11 <link rel="prev" href="stl_db_usage.html" title="Berkeley DB configuration" />
12 <link rel="next" href="stl_txn_usage.html" title="Using transactions in dbstl" />
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">Using advanced Berkeley DB features with dbstl</th>
22 </tr>
23 <tr>
24 <td width="20%" align="left"><a accesskey="p" href="stl_db_usage.html">Prev</a> </td>
25 <th width="60%" align="center">Chapter 7. Standard Template Library API</th>
26 <td width="20%" align="right"> <a accesskey="n" href="stl_txn_usage.html">Next</a></td>
27 </tr>
28 </table>
29 <hr />
30 </div>
31 <div class="sect1" lang="en" xml:lang="en">
32 <div class="titlepage">
33 <div>
34 <div>
35 <h2 class="title" style="clear: both"><a id="stl_db_advanced_usage"></a>Using advanced Berkeley DB features with dbstl</h2>
36 </div>
37 </div>
38 </div>
39 <div class="toc">
40 <dl>
41 <dt>
42 <span class="sect2">
43 <a href="stl_db_advanced_usage.html#idp51421384">Using bulk retrieval iterators</a>
44 </span>
45 </dt>
46 <dt>
47 <span class="sect2">
48 <a href="stl_db_advanced_usage.html#idp51410312">Using the DB_RMW flag</a>
49 </span>
50 </dt>
51 <dt>
52 <span class="sect2">
53 <a href="stl_db_advanced_usage.html#idp51398048">Using secondary index database and secondary containers</a>
54 </span>
55 </dt>
56 </dl>
57 </div>
58 <p>
59 This section describes advanced Berkeley DB features that are
60 available through dbstl.
61 </p>
62 <div class="sect2" lang="en" xml:lang="en">
63 <div class="titlepage">
64 <div>
65 <div>
66 <h3 class="title"><a id="idp51421384"></a>Using bulk retrieval iterators</h3>
67 </div>
68 </div>
69 </div>
70 <p>
71 Bulk retrieval is an optimization option for const iterators and
72 nonconst but read-only iterators. Bulk retrieval can minimize the
73 number of database accesses performed by your application. It does this
74 by reading multiple entries at a time, which reduces read overhead.
75 Note that non-sequential reads will benefit less from, or even be hurt
76 by, this behavior, because it might result in unneeded data being read
77 from the database. Also, non-serializable reads may read obsolete
78 data, because part of the data read from the bulk read buffer may have
79 been updated since the retrieval.
80 </p>
81 <p>
82 When using the default transaction isolation, iterators will perform
83 serializable reads. In this situation, the bulk-retrieved data cannot
84 be updated until the iterator's cursor is closed.
85 </p>
86 <p>
87 Iterators using a different isolation levels, such as
88 <a href="../api_reference/C/dbcget.html#dbcget_DB_READ_COMMITTED" class="olink">DB_READ_COMMITTED</a> or <a href="../api_reference/C/dbopen.html#dbopen_DB_READ_UNCOMMITTED" class="olink">DB_READ_UNCOMMITTED</a> will not perform
89 serializable reads. The same is true for any iterators that do not use
90 transactions.
91 </p>
92 <p>
93 A bulk retrieval iterator can only move in a singled direction, from
94 beginning to end. This means that iterators only support operator++,
95 and reverse iterators only support operator--.
96 </p>
97 <p>
98 Iterator objects that use bulk retrieval might contain hundreds of
99 kilobytes of data, which makes copying the iterator object an expensive
100 operation. If possible, use ++iterator rather than iterator++. This
101 can save a useless copy construction of the iterator, as well as an
102 unnecessary dup/close of the cursor.
103 </p>
104 <p>
105 You can configure bulk retrieval for each container using both in the
106 const and non-const version of the <code class="methodname">begin()</code>
107 method. The non-const version of <code class="methodname">begin()</code> will
108 return a read-only cursor. Note that read-only means something
109 different in C++ than it does when referring to an iterator. The latter
110 only means that it cannot be used to update the database.
111 </p>
112 <p>
113 To configure the bulk retrieval buffer for an iterator when calling the
114 <code class="methodname">begin()</code> method, use the
115 <code class="function">BulkRetrievelItrOpt::bulk_retrieval(u_int32_t bulk_buffer_size)</code>
116 function.
117 </p>
118 <p>
119 If you move a <code class="classname">db_vector_iterator</code> randomly rather
120 than sequentially, then dbstl will not perform bulk retrieval because
121 there is little performance gain from bulk retrieval in such an access
122 pattern.
123 </p>
124 <p>
125 You can call <code class="function">iterator::set_bulk_buffer()</code> to modify
126 the iterator's bulk buffer size. Note that once bulk read is enabled,
127 only the bulk buffer size can be modified. This means that bulk read
128 cannot be disabled. Also, if bulk read was not enabled when you created
129 the iterator, you can't enable it after creation.
130 </p>
131 <p>
132 Example code using this feature can be found in the
133 <code class="methodname">StlAdvancedFeaturesExample::bulk_retrieval_read()</code> method.
134 </p>
135 </div>
136 <div class="sect2" lang="en" xml:lang="en">
137 <div class="titlepage">
138 <div>
139 <div>
140 <h3 class="title"><a id="idp51410312"></a>Using the DB_RMW flag</h3>
141 </div>
142 </div>
143 </div>
144 <p>
145 The <a href="../api_reference/C/dbcget.html#dbcget_DB_RMW" class="olink">DB_RMW</a> flag is an optimization for non-const (read-write)
146 iterators. This flag causes the underlying cursor to acquire a write
147 lock when reading so as to avoid deadlocks. Passing
148 <code class="function">ReadModifyWriteOption::read_modify_write()</code> to a
149 container's <code class="methodname">begin()</code> method creates an iterator
150 whose cursor has this behavior.
151 </p>
152 </div>
153 <div class="sect2" lang="en" xml:lang="en">
154 <div class="titlepage">
155 <div>
156 <div>
157 <h3 class="title"><a id="idp51398048"></a>Using secondary index database and secondary containers</h3>
158 </div>
159 </div>
160 </div>
161 <p>
162 Because duplicate keys are forbidden in primary databases, only
163 <code class="classname">db_map</code>, <code class="classname">db_set</code> and
164 <code class="classname">db_vector</code> are allowed to use primary databases.
165 For this reason, they are called
166 <span class="bold"><strong>primary containers</strong></span>.
167 A secondary database that supports duplicate keys can be used with
168 <code class="classname">db_multimap</code> containers. These are called
169 <span class="bold"><strong>secondary containers</strong></span>. Finally, a
170 secondary database that forbids duplicate keys can back a
171 <code class="classname">db_map</code> container.
172 </p>
173 <p>
174 The <span class="bold"><strong>data_type</strong></span> of this
175 <code class="classname">db_multimap</code> secondary container is the
176 <span class="bold"><strong>data_type</strong></span> for the primary container. For
177 example, a <code class="classname">db_map&lt;int, Person&gt;</code> object
178 where the <code class="classname">Person</code> class has an
179 <code class="literal">age</code> property of type <code class="literal">size_t</code>, a
180 <code class="classname">db_multimap&lt;size_t, Person&gt;</code> using a
181 secondary database allows access to a person by age.
182 </p>
183 <p>
184
185 A container created from a secondary database can only be used to
186 iterate, search or delete. It can not be used to update or insert.
187 While dbstl does expose the update and insert operations, Berkeley DB
188 does not, and an exception will be thrown if attempts are made to
189 insert objects into or update objects of a secondary container.
190 </p>
191 <p>
192 Example code demonstrating this feature is available in the
193 <code class="methodname">StlAdvancedFeaturesExample::secondary_containers()</code> method.
194 </p>
195 </div>
196 </div>
197 <div class="navfooter">
198 <hr />
199 <table width="100%" summary="Navigation footer">
200 <tr>
201 <td width="40%" align="left"><a accesskey="p" href="stl_db_usage.html">Prev</a> </td>
202 <td width="20%" align="center">
203 <a accesskey="u" href="stl.html">Up</a>
204 </td>
205 <td width="40%" align="right"> <a accesskey="n" href="stl_txn_usage.html">Next</a></td>
206 </tr>
207 <tr>
208 <td width="40%" align="left" valign="top">Berkeley DB configuration </td>
209 <td width="20%" align="center">
210 <a accesskey="h" href="index.html">Home</a>
211 </td>
212 <td width="40%" align="right" valign="top"> Using transactions in dbstl</td>
213 </tr>
214 </table>
215 </div>
216 </body>
217 </html>