| 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>Chapter 2. Locking Notes</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="Getting Started with the Oracle Berkeley DB SQL APIs" /> |
| 10 | <link rel="up" href="index.html" title="Getting Started with the Oracle Berkeley DB SQL APIs" /> |
| 11 | <link rel="prev" href="normal-sql.html" title="Differences for Users of other SQL Engines" /> |
| 12 | <link rel="next" href="lockhandling.html" title="Lock Handling" /> |
| 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">Chapter 2. Locking Notes</th> |
| 22 | </tr> |
| 23 | <tr> |
| 24 | <td width="20%" align="left"><a accesskey="p" href="normal-sql.html">Prev</a> </td> |
| 25 | <th width="60%" align="center"> </th> |
| 26 | <td width="20%" align="right"> <a accesskey="n" href="lockhandling.html">Next</a></td> |
| 27 | </tr> |
| 28 | </table> |
| 29 | <hr /> |
| 30 | </div> |
| 31 | <div class="chapter" lang="en" xml:lang="en"> |
| 32 | <div class="titlepage"> |
| 33 | <div> |
| 34 | <div> |
| 35 | <h2 class="title"><a id="lockingnotes"></a>Chapter 2. Locking Notes</h2> |
| 36 | </div> |
| 37 | </div> |
| 38 | </div> |
| 39 | <div class="toc"> |
| 40 | <p> |
| 41 | <b>Table of Contents</b> |
| 42 | </p> |
| 43 | <dl> |
| 44 | <dt> |
| 45 | <span class="sect1"> |
| 46 | <a href="lockingnotes.html#dbusage">Internal Database Usage</a> |
| 47 | </span> |
| 48 | </dt> |
| 49 | <dt> |
| 50 | <span class="sect1"> |
| 51 | <a href="lockhandling.html">Lock Handling</a> |
| 52 | </span> |
| 53 | </dt> |
| 54 | <dd> |
| 55 | <dl> |
| 56 | <dt> |
| 57 | <span class="sect2"> |
| 58 | <a href="lockhandling.html#sqllockmodel">SQLite Lock Usage</a> |
| 59 | </span> |
| 60 | </dt> |
| 61 | <dt> |
| 62 | <span class="sect2"> |
| 63 | <a href="lockhandling.html#bdblockusage">Lock Usage with the BDB SQL Interface</a> |
| 64 | </span> |
| 65 | </dt> |
| 66 | </dl> |
| 67 | </dd> |
| 68 | </dl> |
| 69 | </div> |
| 70 | <p> |
| 71 | There are some important performance differences between the |
| 72 | BDB SQL interface and SQLite, especially in a concurrent environment. |
| 73 | This chapter gives you enough information about how the BDB SQL interface |
| 74 | uses its database, as opposed to how SQLite uses its |
| 75 | database, in order for you to understand the difference between |
| 76 | the two interfaces. It then gives you some advice on how to |
| 77 | best approach working with the BDB SQL interface in a multi-threaded |
| 78 | environment. |
| 79 | </p> |
| 80 | <p> |
| 81 | If you are an existing user of SQLite, and you care about |
| 82 | improving your application performance when using the BDB SQL interface in |
| 83 | a concurrent situation, you should read this chapter. Existing |
| 84 | users of Berkeley DB may also find some interesting information in |
| 85 | this chapter, although it is mostly geared towards SQLite |
| 86 | users. |
| 87 | </p> |
| 88 | <div class="sect1" lang="en" xml:lang="en"> |
| 89 | <div class="titlepage"> |
| 90 | <div> |
| 91 | <div> |
| 92 | <h2 class="title" style="clear: both"><a id="dbusage"></a>Internal Database Usage</h2> |
| 93 | </div> |
| 94 | </div> |
| 95 | </div> |
| 96 | <p> |
| 97 | The BDB SQL interface and SQLite do different things |
| 98 | when it comes to locking data in their databases. In order |
| 99 | to provide ACID transactions, both products must prevent |
| 100 | concurrent access during write operations. Further, both |
| 101 | products prevent concurrent access by obtaining software |
| 102 | level locks that allow only the current holder of the lock to |
| 103 | perform write access to the locked data. |
| 104 | </p> |
| 105 | <p> |
| 106 | The difference between the two is that when SQLite |
| 107 | requires a lock (such as when a transaction is underway), it |
| 108 | locks the entire database and all tables. (This is known as |
| 109 | <span class="emphasis"><em>database level locking</em></span>.) The BDB SQL interface, on the |
| 110 | other hand, only locks the portion of the table being |
| 111 | operated on within the current transactional context (this is |
| 112 | known as <span class="emphasis"><em>page level locking</em></span>). In most |
| 113 | situations, this allows applications using the BDB SQL interface to |
| 114 | operate concurrently and so have better read/write |
| 115 | throughput than applications using SQLite. |
| 116 | This is because there is less lock contention. |
| 117 | </p> |
| 118 | <p> |
| 119 | By default, one Berkeley DB logical database is created within the |
| 120 | single database file for every SQL table that you create. Within |
| 121 | each such logical database, each table row is represented as a |
| 122 | Berkeley DB key/data pair. |
| 123 | </p> |
| 124 | <p> |
| 125 | This is important because the BDB SQL interface uses Berkeley DB's Transaction |
| 126 | Data Store product. This means that Berkeley DB does not have to |
| 127 | lock an entire database (all the tables within a database |
| 128 | file) when it acquires a lock. Instead, it locks a single |
| 129 | Berkeley DB database page (which usually contains a small sub-set |
| 130 | of rows within a single table). |
| 131 | </p> |
| 132 | <p> |
| 133 | The size of database pages will differ from platform to |
| 134 | platform (you can also manually configure this), but usually |
| 135 | a database page can hold multiple key/data pairs; that is, |
| 136 | multiple rows from a SQL table. Exactly how many table |
| 137 | rows fit on a database page depends on the size of your page |
| 138 | and the size of your table rows. |
| 139 | </p> |
| 140 | <p> |
| 141 | If you have an exceptionally small table, it is possible for |
| 142 | the entire table to fit on a single database page. In this |
| 143 | case, Berkeley DB is in essence forced to serialize access to the |
| 144 | entire table when it requires a lock for it. |
| 145 | </p> |
| 146 | <p> |
| 147 | Note, however, that the case of a single table fitting on a |
| 148 | single database page is very rare, and it in fact represents the |
| 149 | abnormal case. Normally tables span multiple pages and so Berkeley DB |
| 150 | will lock only portions of your tables. This locking behavior is |
| 151 | automatic and transparent to your application. |
| 152 | </p> |
| 153 | </div> |
| 154 | </div> |
| 155 | <div class="navfooter"> |
| 156 | <hr /> |
| 157 | <table width="100%" summary="Navigation footer"> |
| 158 | <tr> |
| 159 | <td width="40%" align="left"><a accesskey="p" href="normal-sql.html">Prev</a> </td> |
| 160 | <td width="20%" align="center"> </td> |
| 161 | <td width="40%" align="right"> <a accesskey="n" href="lockhandling.html">Next</a></td> |
| 162 | </tr> |
| 163 | <tr> |
| 164 | <td width="40%" align="left" valign="top">Differences for Users of other SQL Engines </td> |
| 165 | <td width="20%" align="center"> |
| 166 | <a accesskey="h" href="index.html">Home</a> |
| 167 | </td> |
| 168 | <td width="40%" align="right" valign="top"> Lock Handling</td> |
| 169 | </tr> |
| 170 | </table> |
| 171 | </div> |
| 172 | </body> |
| 173 | </html> |