| 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>Mapping the terrain: theory and practice</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="intro.html" title="Chapter 1. Introduction" /> |
| 11 | <link rel="prev" href="intro.html" title="Chapter 1. Introduction" /> |
| 12 | <link rel="next" href="intro_dbis.html" title="What is Berkeley DB?" /> |
| 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">Mapping the terrain: theory and practice</th> |
| 22 | </tr> |
| 23 | <tr> |
| 24 | <td width="20%" align="left"><a accesskey="p" href="intro.html">Prev</a> </td> |
| 25 | <th width="60%" align="center">Chapter 1. |
| 26 | Introduction |
| 27 | </th> |
| 28 | <td width="20%" align="right"> <a accesskey="n" href="intro_dbis.html">Next</a></td> |
| 29 | </tr> |
| 30 | </table> |
| 31 | <hr /> |
| 32 | </div> |
| 33 | <div class="sect1" lang="en" xml:lang="en"> |
| 34 | <div class="titlepage"> |
| 35 | <div> |
| 36 | <div> |
| 37 | <h2 class="title" style="clear: both"><a id="intro_terrain"></a>Mapping the terrain: theory and practice</h2> |
| 38 | </div> |
| 39 | </div> |
| 40 | </div> |
| 41 | <div class="toc"> |
| 42 | <dl> |
| 43 | <dt> |
| 44 | <span class="sect2"> |
| 45 | <a href="intro_terrain.html#idp50584200">Data access and data management</a> |
| 46 | </span> |
| 47 | </dt> |
| 48 | <dt> |
| 49 | <span class="sect2"> |
| 50 | <a href="intro_terrain.html#idp50577368">Relational databases</a> |
| 51 | </span> |
| 52 | </dt> |
| 53 | <dt> |
| 54 | <span class="sect2"> |
| 55 | <a href="intro_terrain.html#idp50621160">Object-oriented databases</a> |
| 56 | </span> |
| 57 | </dt> |
| 58 | <dt> |
| 59 | <span class="sect2"> |
| 60 | <a href="intro_terrain.html#idp50574144">Network databases</a> |
| 61 | </span> |
| 62 | </dt> |
| 63 | <dt> |
| 64 | <span class="sect2"> |
| 65 | <a href="intro_terrain.html#idp50647776">Clients and servers</a> |
| 66 | </span> |
| 67 | </dt> |
| 68 | </dl> |
| 69 | </div> |
| 70 | <p>The first step in selecting a database system is figuring out what the |
| 71 | choices are. Decades of research and real-world deployment have produced |
| 72 | countless systems. We need to organize them somehow to reduce the number |
| 73 | of options.</p> |
| 74 | <p>One obvious way to group systems is to use the common labels that |
| 75 | vendors apply to them. The buzzwords here include "network," |
| 76 | "relational," "object-oriented," and "embedded," with some |
| 77 | cross-fertilization like "object-relational" and "embedded network". |
| 78 | Understanding the buzzwords is important. Each has some grounding in |
| 79 | theory, but has also evolved into a practical label for categorizing |
| 80 | systems that work in a certain way.</p> |
| 81 | <p>All database systems, regardless of the buzzwords that apply to them, |
| 82 | provide a few common services. All of them store data, for example. |
| 83 | We'll begin by exploring the common services that all systems provide, |
| 84 | and then examine the differences among the different kinds of systems.</p> |
| 85 | <div class="sect2" lang="en" xml:lang="en"> |
| 86 | <div class="titlepage"> |
| 87 | <div> |
| 88 | <div> |
| 89 | <h3 class="title"><a id="idp50584200"></a>Data access and data management</h3> |
| 90 | </div> |
| 91 | </div> |
| 92 | </div> |
| 93 | <p>Fundamentally, database systems provide two services.</p> |
| 94 | <p>The first service is <span class="emphasis"><em>data access</em></span>. Data access means adding |
| 95 | new data to the database (inserting), finding data of interest |
| 96 | (searching), changing data already stored (updating), and removing data |
| 97 | from the database (deleting). All databases provide these services. How |
| 98 | they work varies from category to category, and depends on the record |
| 99 | structure that the database supports.</p> |
| 100 | <p>Each record in a database is a collection of values. For example, the |
| 101 | record for a Web site customer might include a name, email address, |
| 102 | shipping address, and payment information. Records are usually stored |
| 103 | in tables. Each table holds records of the same kind. For example, the |
| 104 | <span class="bold"><strong>customer</strong></span> table at an e-commerce Web site might store the |
| 105 | customer records for every person who shopped at the site. Often, |
| 106 | database records have a different structure from the structures or |
| 107 | instances supported by the programming language in which an application |
| 108 | is written. As a result, working with records can mean:</p> |
| 109 | <div class="itemizedlist"> |
| 110 | <ul type="disc"> |
| 111 | <li>using database operations like searches and updates on records; and</li> |
| 112 | <li>converting between programming language structures and database record |
| 113 | types in the application.</li> |
| 114 | </ul> |
| 115 | </div> |
| 116 | <p>The second service is <span class="emphasis"><em>data management</em></span>. Data management is |
| 117 | more complicated than data access. Providing good data management |
| 118 | services is the hard part of building a database system. When you |
| 119 | choose a database system to use in an application you build, making sure |
| 120 | it supports the data management services you need is critical.</p> |
| 121 | <p>Data management services include allowing multiple users to work on the |
| 122 | database simultaneously (concurrency), allowing multiple records to be |
| 123 | changed instantaneously (transactions), and surviving application and |
| 124 | system crashes (recovery). Different database systems offer different |
| 125 | data management services. Data management services are entirely |
| 126 | independent of the data access services listed above. For example, |
| 127 | nothing about relational database theory requires that the system |
| 128 | support transactions, but most commercial relational systems do.</p> |
| 129 | <p>Concurrency means that multiple users can operate on the database at |
| 130 | the same time. Support for concurrency ranges from none (single-user |
| 131 | access only) to complete (many readers and writers working |
| 132 | simultaneously).</p> |
| 133 | <p>Transactions permit users to make multiple changes appear at once. For |
| 134 | example, a transfer of funds between bank accounts needs to be a |
| 135 | transaction because the balance in one account is reduced and the |
| 136 | balance in the other increases. If the reduction happened before the |
| 137 | increase, than a poorly-timed system crash could leave the customer |
| 138 | poorer; if the bank used the opposite order, then the same system crash |
| 139 | could make the customer richer. Obviously, both the customer and the |
| 140 | bank are best served if both operations happen at the same instant.</p> |
| 141 | <p>Transactions have well-defined properties in database systems. They are |
| 142 | <span class="emphasis"><em>atomic</em></span>, so that the changes happen all at once or not at all. |
| 143 | They are <span class="emphasis"><em>consistent</em></span>, so that the database is in a legal state |
| 144 | when the transaction begins and when it ends. They are typically |
| 145 | <span class="emphasis"><em>isolated</em></span>, which means that any other users in the database |
| 146 | cannot interfere with them while they are in progress. And they are |
| 147 | <span class="emphasis"><em>durable</em></span>, so that if the system or application crashes after |
| 148 | a transaction finishes, the changes are not lost. Together, the |
| 149 | properties of <span class="emphasis"><em>atomicity</em></span>, <span class="emphasis"><em>consistency</em></span>, |
| 150 | <span class="emphasis"><em>isolation</em></span>, and <span class="emphasis"><em>durability</em></span> are known as the ACID |
| 151 | properties.</p> |
| 152 | <p>As is the case for concurrency, support for transactions varies among |
| 153 | databases. Some offer atomicity without making guarantees about |
| 154 | durability. Some ignore isolatability, especially in single-user |
| 155 | systems; there's no need to isolate other users from the effects of |
| 156 | changes when there are no other users.</p> |
| 157 | <p>Another important data management service is recovery. Strictly |
| 158 | speaking, recovery is a procedure that the system carries out when it |
| 159 | starts up. The purpose of recovery is to guarantee that the database is |
| 160 | complete and usable. This is most important after a system or |
| 161 | application crash, when the database may have been damaged. The recovery |
| 162 | process guarantees that the internal structure of the database is good. |
| 163 | Recovery usually means that any completed transactions are checked, and |
| 164 | any lost changes are reapplied to the database. At the end of the |
| 165 | recovery process, applications can use the database as if there had been |
| 166 | no interruption in service.</p> |
| 167 | <p>Finally, there are a number of data management services that permit |
| 168 | copying of data. For example, most database systems are able to import |
| 169 | data from other sources, and to export it for use elsewhere. Also, most |
| 170 | systems provide some way to back up databases and to restore in the |
| 171 | event of a system failure that damages the database. Many commercial |
| 172 | systems allow <span class="emphasis"><em>hot backups</em></span>, so that users can back up |
| 173 | databases while they are in use. Many applications must run without |
| 174 | interruption, and cannot be shut down for backups.</p> |
| 175 | <p>A particular database system may provide other data management services. |
| 176 | Some provide browsers that show database structure and contents. Some |
| 177 | include tools that enforce data integrity rules, such as the rule that |
| 178 | no employee can have a negative salary. These data management services |
| 179 | are not common to all systems, however. Concurrency, recovery, and |
| 180 | transactions are the data management services that most database vendors |
| 181 | support.</p> |
| 182 | <p>Deciding what kind of database to use means understanding the data |
| 183 | access and data management services that your application needs. Berkeley DB |
| 184 | is an embedded database that supports fairly simple data access with a |
| 185 | rich set of data management services. To highlight its strengths and |
| 186 | weaknesses, we can compare it to other database system categories.</p> |
| 187 | </div> |
| 188 | <div class="sect2" lang="en" xml:lang="en"> |
| 189 | <div class="titlepage"> |
| 190 | <div> |
| 191 | <div> |
| 192 | <h3 class="title"><a id="idp50577368"></a>Relational databases</h3> |
| 193 | </div> |
| 194 | </div> |
| 195 | </div> |
| 196 | <p>Relational databases are probably the best-known database variant, |
| 197 | because of the success of companies like Oracle. Relational databases |
| 198 | are based on the mathematical field of set theory. The term "relation" |
| 199 | is really just a synonym for "set" -- a relation is just a set of |
| 200 | records or, in our terminology, a table. One of the main innovations in |
| 201 | early relational systems was to insulate the programmer from the |
| 202 | physical organization of the database. Rather than walking through |
| 203 | arrays of records or traversing pointers, programmers make statements |
| 204 | about tables in a high-level language, and the system executes those |
| 205 | statements.</p> |
| 206 | <p>Relational databases operate on <span class="emphasis"><em>tuples</em></span>, or records, composed |
| 207 | of values of several different data types, including integers, character |
| 208 | strings, and others. Operations include searching for records whose |
| 209 | values satisfy some criteria, updating records, and so on.</p> |
| 210 | <p>Virtually all relational databases use the Structured Query Language, |
| 211 | or SQL. This language permits people and computer programs to work with |
| 212 | the database by writing simple statements. The database engine reads |
| 213 | those statements and determines how to satisfy them on the tables in |
| 214 | the database.</p> |
| 215 | <p>SQL is the main practical advantage of relational database systems. |
| 216 | Rather than writing a computer program to find records of interest, the |
| 217 | relational system user can just type a query in a simple syntax, and |
| 218 | let the engine do the work. This gives users enormous flexibility; they |
| 219 | do not need to decide in advance what kind of searches they want to do, |
| 220 | and they do not need expensive programmers to find the data they need. |
| 221 | Learning SQL requires some effort, but it's much simpler than a |
| 222 | full-blown high-level programming language for most purposes. And there |
| 223 | are a lot of programmers who have already learned SQL.</p> |
| 224 | </div> |
| 225 | <div class="sect2" lang="en" xml:lang="en"> |
| 226 | <div class="titlepage"> |
| 227 | <div> |
| 228 | <div> |
| 229 | <h3 class="title"><a id="idp50621160"></a>Object-oriented databases</h3> |
| 230 | </div> |
| 231 | </div> |
| 232 | </div> |
| 233 | <p>Object-oriented databases are less common than relational systems, but |
| 234 | are still fairly widespread. Most object-oriented databases were |
| 235 | originally conceived as persistent storage systems closely wedded to |
| 236 | particular high-level programming languages like C++. With the spread |
| 237 | of Java, most now support more than one programming language, but |
| 238 | object-oriented database systems fundamentally provide the same class |
| 239 | and method abstractions as do object-oriented programming languages.</p> |
| 240 | <p>Many object-oriented systems allow applications to operate on objects |
| 241 | uniformly, whether they are in memory or on disk. These systems create |
| 242 | the illusion that all objects are in memory all the time. The advantage |
| 243 | to object-oriented programmers who simply want object storage and |
| 244 | retrieval is clear. They need never be aware of whether an object is in |
| 245 | memory or not. The application simply uses objects, and the database |
| 246 | system moves them between disk and memory transparently. All of the |
| 247 | operations on an object, and all its behavior, are determined by the |
| 248 | programming language.</p> |
| 249 | <p>Object-oriented databases aren't nearly as widely deployed as relational |
| 250 | systems. In order to attract developers who understand relational |
| 251 | systems, many of the object-oriented systems have added support for |
| 252 | query languages very much like SQL. In practice, though, object-oriented |
| 253 | databases are mostly used for persistent storage of objects in C++ and |
| 254 | Java programs.</p> |
| 255 | </div> |
| 256 | <div class="sect2" lang="en" xml:lang="en"> |
| 257 | <div class="titlepage"> |
| 258 | <div> |
| 259 | <div> |
| 260 | <h3 class="title"><a id="idp50574144"></a>Network databases</h3> |
| 261 | </div> |
| 262 | </div> |
| 263 | </div> |
| 264 | <p>The "network model" is a fairly old technique for managing and |
| 265 | navigating application data. Network databases are designed to make |
| 266 | pointer traversal very fast. Every record stored in a network database |
| 267 | is allowed to contain pointers to other records. These pointers are |
| 268 | generally physical addresses, so fetching the record to which it refers |
| 269 | just means reading it from disk by its disk address.</p> |
| 270 | <p>Network database systems generally permit records to contain integers, |
| 271 | floating point numbers, and character strings, as well as references to |
| 272 | other records. An application can search for records of interest. After |
| 273 | retrieving a record, the application can fetch any record to which it |
| 274 | refers, quickly.</p> |
| 275 | <p>Pointer traversal is fast because most network systems use physical disk |
| 276 | addresses as pointers. When the application wants to fetch a record, |
| 277 | the database system uses the address to fetch exactly the right string |
| 278 | of bytes from the disk. This requires only a single disk access in all |
| 279 | cases. Other systems, by contrast, often must do more than one disk read |
| 280 | to find a particular record.</p> |
| 281 | <p>The key advantage of the network model is also its main drawback. The |
| 282 | fact that pointer traversal is so fast means that applications that do |
| 283 | it will run well. On the other hand, storing pointers all over the |
| 284 | database makes it very hard to reorganize the database. In effect, once |
| 285 | you store a pointer to a record, it is difficult to move that record |
| 286 | elsewhere. Some network databases handle this by leaving forwarding |
| 287 | pointers behind, but this defeats the speed advantage of doing a single |
| 288 | disk access in the first place. Other network databases find, and fix, |
| 289 | all the pointers to a record when it moves, but this makes |
| 290 | reorganization very expensive. Reorganization is often necessary in |
| 291 | databases, since adding and deleting records over time will consume |
| 292 | space that cannot be reclaimed without reorganizing. Without periodic |
| 293 | reorganization to compact network databases, they can end up with a |
| 294 | considerable amount of wasted space.</p> |
| 295 | </div> |
| 296 | <div class="sect2" lang="en" xml:lang="en"> |
| 297 | <div class="titlepage"> |
| 298 | <div> |
| 299 | <div> |
| 300 | <h3 class="title"><a id="idp50647776"></a>Clients and servers</h3> |
| 301 | </div> |
| 302 | </div> |
| 303 | </div> |
| 304 | <p>Database vendors have two choices for system architecture. They can |
| 305 | build a server to which remote clients connect, and do all the database |
| 306 | management inside the server. Alternatively, they can provide a module |
| 307 | that links directly into the application, and does all database |
| 308 | management locally. In either case, the application developer needs |
| 309 | some way of communicating with the database (generally, an Application |
| 310 | Programming Interface (API) that does work in the process or that |
| 311 | communicates with a server to get work done).</p> |
| 312 | <p>Almost all commercial database products are implemented as servers, and |
| 313 | applications connect to them as clients. Servers have several features |
| 314 | that make them attractive.</p> |
| 315 | <p>First, because all of the data is managed by a separate process, and |
| 316 | possibly on a separate machine, it's easy to isolate the database server |
| 317 | from bugs and crashes in the application.</p> |
| 318 | <p>Second, because some database products (particularly relational engines) |
| 319 | are quite large, splitting them off as separate server processes keeps |
| 320 | applications small, which uses less disk space and memory. Relational |
| 321 | engines include code to parse SQL statements, to analyze them and |
| 322 | produce plans for execution, to optimize the plans, and to execute |
| 323 | them.</p> |
| 324 | <p>Finally, by storing all the data in one place and managing it with a |
| 325 | single server, it's easier for organizations to back up, protect, and |
| 326 | set policies on their databases. The enterprise databases for large |
| 327 | companies often have several full-time administrators caring for them, |
| 328 | making certain that applications run quickly, granting and denying |
| 329 | access to users, and making backups.</p> |
| 330 | <p>However, centralized administration can be a disadvantage in some cases. |
| 331 | In particular, if a programmer wants to build an application that uses |
| 332 | a database for storage of important information, then shipping and |
| 333 | supporting the application is much harder. The end user needs to install |
| 334 | and administer a separate database server, and the programmer must |
| 335 | support not just one product, but two. Adding a server process to the |
| 336 | application creates new opportunity for installation mistakes and |
| 337 | run-time problems.</p> |
| 338 | </div> |
| 339 | </div> |
| 340 | <div class="navfooter"> |
| 341 | <hr /> |
| 342 | <table width="100%" summary="Navigation footer"> |
| 343 | <tr> |
| 344 | <td width="40%" align="left"><a accesskey="p" href="intro.html">Prev</a> </td> |
| 345 | <td width="20%" align="center"> |
| 346 | <a accesskey="u" href="intro.html">Up</a> |
| 347 | </td> |
| 348 | <td width="40%" align="right"> <a accesskey="n" href="intro_dbis.html">Next</a></td> |
| 349 | </tr> |
| 350 | <tr> |
| 351 | <td width="40%" align="left" valign="top">Chapter 1. |
| 352 | Introduction |
| 353 | </td> |
| 354 | <td width="20%" align="center"> |
| 355 | <a accesskey="h" href="index.html">Home</a> |
| 356 | </td> |
| 357 | <td width="40%" align="right" valign="top"> What is Berkeley DB?</td> |
| 358 | </tr> |
| 359 | </table> |
| 360 | </div> |
| 361 | </body> |
| 362 | </html> |