| 1 |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> |
| 2 |
<!-- |
| 3 |
Copyright 2004-2019 H2 Group. Multiple-Licensed under the MPL 2.0, |
| 4 |
and the EPL 1.0 (http://h2database.com/html/license.html). |
| 5 |
Initial Developer: H2 Group |
| 6 |
--> |
| 7 |
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"> |
| 8 |
<head> |
| 9 |
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" /> |
| 10 |
<meta name="viewport" content="width=device-width, initial-scale=1" /> |
| 11 |
<title> |
| 12 |
Architecture |
| 13 |
</title> |
| 14 |
<link rel="stylesheet" type="text/css" href="stylesheet.css" /> |
| 15 |
<!-- [search] { --> |
| 16 |
<script type="text/javascript" src="navigation.js"></script> |
| 17 |
</head><body onload="frameMe();"> |
| 18 |
<table class="content"><tr class="content"><td class="content"><div class="contentDiv"> |
| 19 |
<!-- } --> |
| 20 |
|
| 21 |
<h1>Architecture</h1> |
| 22 |
<a href="#introduction"> |
| 23 |
Introduction</a><br /> |
| 24 |
<a href="#top_down"> |
| 25 |
Top-down overview</a><br /> |
| 26 |
<a href="#jdbc"> |
| 27 |
JDBC driver</a><br /> |
| 28 |
<a href="#connection"> |
| 29 |
Connection/session management</a><br /> |
| 30 |
<a href="#command"> |
| 31 |
Command execution and planning</a><br /> |
| 32 |
<a href="#table"> |
| 33 |
Table/index/constraints</a><br /> |
| 34 |
<a href="#transaction"> |
| 35 |
Undo log, redo log, and transactions layer</a><br /> |
| 36 |
<a href="#btree"> |
| 37 |
B-tree engine and page-based storage allocation</a><br /> |
| 38 |
<a href="#filesystem"> |
| 39 |
Filesystem abstraction</a><br /> |
| 40 |
|
| 41 |
<h2 id="introduction">Introduction</h2> |
| 42 |
<p> |
| 43 |
H2 implements an embedded and standalone ANSI-SQL89 compliant SQL engine on top of a B-tree based disk store. |
| 44 |
</p> |
| 45 |
<p> |
| 46 |
As of October 2013, Thomas is still working on our next-generation storage engine called MVStore. This will |
| 47 |
in time replace the B-tree based storage engine. |
| 48 |
</p> |
| 49 |
|
| 50 |
<h2 id="top_down">Top-down Overview</h2> |
| 51 |
<p> |
| 52 |
Working from the top down, the layers look like this: |
| 53 |
<ul><li>JDBC driver. |
| 54 |
</li><li>Connection/session management. |
| 55 |
</li><li>SQL Parser. |
| 56 |
</li><li>Command execution and planning. |
| 57 |
</li><li>Table/Index/Constraints. |
| 58 |
</li><li>Undo log, redo log, and transactions layer. |
| 59 |
</li><li>B-tree engine and page-based storage allocation. |
| 60 |
</li><li>Filesystem abstraction. |
| 61 |
</li></ul> |
| 62 |
</p> |
| 63 |
|
| 64 |
<h2 id="jdbc">JDBC Driver</h2> |
| 65 |
<p> |
| 66 |
The JDBC driver implementation lives in <code>org.h2.jdbc, org.h2.jdbcx</code> |
| 67 |
</p> |
| 68 |
|
| 69 |
<h2 id="connection">Connection/session management</h2> |
| 70 |
<p> |
| 71 |
The primary classes of interest are: |
| 72 |
<table class="main"> |
| 73 |
<tr><th>Package</th><th>Description</th></tr> |
| 74 |
<tr><td>org.h2.engine.Database</td><td>the root/global class</td></tr> |
| 75 |
<tr><td>org.h2.engine.SessionInterface</td> |
| 76 |
<td>abstracts over the differences between embedded and remote sessions</td></tr> |
| 77 |
<tr><td>org.h2.engine.Session</td> |
| 78 |
<td>local/embedded session</td></tr> |
| 79 |
<tr><td>org.h2.engine.SessionRemote</td> |
| 80 |
<td>remote session</td></tr> |
| 81 |
</table> |
| 82 |
</p> |
| 83 |
|
| 84 |
<h2 id="jdbc">Parser</h2> |
| 85 |
<p> |
| 86 |
The parser lives in <code>org.h2.command.Parser</code>. It uses a straightforward recursive-descent design. |
| 87 |
</p> |
| 88 |
<p> |
| 89 |
See Wikipedia <a href="https://en.wikipedia.org/wiki/Recursive_descent_parser">Recursive descent parser</a> page. |
| 90 |
</p> |
| 91 |
|
| 92 |
|
| 93 |
<h2 id="command">Command execution and planning</h2> |
| 94 |
<p> |
| 95 |
Unlike other databases, we do not have an intermediate step where we generate some kind of IR (intermediate representation) of the query. |
| 96 |
The parser class directly generates a command execution object. |
| 97 |
Then we run some optimisation steps over the command to possibly generate a more efficient command. |
| 98 |
|
| 99 |
The primary packages of interest are: |
| 100 |
<table class="main"> |
| 101 |
<tr><th>Package</th><th>Description</th></tr> |
| 102 |
<tr><td>org.h2.command.ddl</td><td>Commands that modify schema data structures</td></tr> |
| 103 |
<tr><td>org.h2.command.dml</td><td>Commands that modify data</td></tr> |
| 104 |
</table> |
| 105 |
</p> |
| 106 |
|
| 107 |
<h2 id="table">Table/Index/Constraints</h2> |
| 108 |
<p> |
| 109 |
One thing to note here is that indexes are simply stored as special kinds of tables. |
| 110 |
</p> |
| 111 |
<p> |
| 112 |
The primary packages of interest are: |
| 113 |
<table class="main"> |
| 114 |
<tr><th>Package</th><th>Description</th></tr> |
| 115 |
<tr><td>org.h2.table</td><td>Implementations of different kinds of tables</td></tr> |
| 116 |
<tr><td>org.h2.index</td><td>Implementations of different kinds of indices</td></tr> |
| 117 |
</table> |
| 118 |
</p> |
| 119 |
|
| 120 |
<h2 id="transaction">Undo log, redo log, and transactions layer</h2> |
| 121 |
<p> |
| 122 |
We have a transaction log, which is shared among all sessions. See also |
| 123 |
<a href="https://en.wikipedia.org/wiki/Transaction_log">https://en.wikipedia.org/wiki/Transaction_log</a> |
| 124 |
<a href="http://h2database.com/html/grammar.html#set_log">http://h2database.com/html/grammar.html#set_log</a> |
| 125 |
</p> |
| 126 |
<p> |
| 127 |
We also have an undo log, which is per session, to undo an operation (an update that fails for example) |
| 128 |
and to rollback a transaction. |
| 129 |
Theoretically, the transaction log could be used, but for simplicity, H2 currently uses it's |
| 130 |
own "list of operations" (usually in-memory). |
| 131 |
</p> |
| 132 |
<p> |
| 133 |
With the MVStore, this is no longer needed (just the transaction log). |
| 134 |
</p> |
| 135 |
|
| 136 |
<h2 id="btree">B-tree engine and page-based storage allocation.</h2> |
| 137 |
<p> |
| 138 |
The primary package of interest is <code>org.h2.store</code>. |
| 139 |
</p> |
| 140 |
<p> |
| 141 |
This implements a storage mechanism which allocates pages of storage (typically 2k in size) |
| 142 |
and also implements a b-tree over those pages to allow fast retrieval and update. |
| 143 |
</p> |
| 144 |
|
| 145 |
<h2 id="filesystem">Filesystem abstraction.</h2> |
| 146 |
<p> |
| 147 |
The primary class of interest is <code>org.h2.store.FileStore</code>. |
| 148 |
</p> |
| 149 |
<p> |
| 150 |
This implements an abstraction of a random-access file. |
| 151 |
This allows the higher layers to treat in-memory vs. on-disk vs. zip-file databases the same. |
| 152 |
</p> |
| 153 |
|
| 154 |
<!-- [close] { --></div></td></tr></table><!-- } --><!-- analytics --></body></html> |