Debian Codegraph @

src/docsrc/html/architecture.html

raw
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-2023 H2 Group. Multiple-Licensed under the MPL 2.0,
4 and the EPL 1.0 (https://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 </p>
54 <ul><li>JDBC driver.
55 </li><li>Connection/session management.
56 </li><li>SQL Parser.
57 </li><li>Command execution and planning.
58 </li><li>Table/Index/Constraints.
59 </li><li>Undo log, redo log, and transactions layer.
60 </li><li>B-tree engine and page-based storage allocation.
61 </li><li>Filesystem abstraction.
62 </li></ul>
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 </p>
73 <table class="main">
74 <tr><th>Package</th><th>Description</th></tr>
75 <tr><td>org.h2.engine.Database</td><td>the root/global class</td></tr>
76 <tr><td>org.h2.engine.SessionInterface</td>
77 <td>abstracts over the differences between embedded and remote sessions</td></tr>
78 <tr><td>org.h2.engine.Session</td>
79 <td>local/embedded session</td></tr>
80 <tr><td>org.h2.engine.SessionRemote</td>
81 <td>remote session</td></tr>
82 </table>
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 </p>
99 <p>
100 The primary packages of interest are:
101 </p>
102 <table class="main">
103 <tr><th>Package</th><th>Description</th></tr>
104 <tr><td>org.h2.command.ddl</td><td>Commands that modify schema data structures</td></tr>
105 <tr><td>org.h2.command.dml</td><td>Commands that modify data</td></tr>
106 </table>
107
108 <h2 id="table">Table/Index/Constraints</h2>
109 <p>
110 One thing to note here is that indexes are simply stored as special kinds of tables.
111 </p>
112 <p>
113 The primary packages of interest are:
114 </p>
115 <table class="main">
116 <tr><th>Package</th><th>Description</th></tr>
117 <tr><td>org.h2.table</td><td>Implementations of different kinds of tables</td></tr>
118 <tr><td>org.h2.index</td><td>Implementations of different kinds of indices</td></tr>
119 </table>
120
121 <h2 id="transaction">Undo log, redo log, and transactions layer</h2>
122 <p>
123 We have a transaction log, which is shared among all sessions. See also
124 <a href="https://en.wikipedia.org/wiki/Transaction_log">https://en.wikipedia.org/wiki/Transaction_log</a>
125 <a href="https://h2database.com/html/grammar.html#set_log">https://h2database.com/html/grammar.html#set_log</a>
126 </p>
127 <p>
128 We also have an undo log, which is per session, to undo an operation (an update that fails for example)
129 and to rollback a transaction.
130 Theoretically, the transaction log could be used, but for simplicity, H2 currently uses it's
131 own "list of operations" (usually in-memory).
132 </p>
133 <p>
134 With the MVStore, this is no longer needed (just the transaction log).
135 </p>
136
137 <h2 id="btree">B-tree engine and page-based storage allocation.</h2>
138 <p>
139 The primary package of interest is <code>org.h2.store</code>.
140 </p>
141 <p>
142 This implements a storage mechanism which allocates pages of storage (typically 2k in size)
143 and also implements a b-tree over those pages to allow fast retrieval and update.
144 </p>
145
146 <h2 id="filesystem">Filesystem abstraction.</h2>
147 <p>
148 The primary class of interest is <code>org.h2.store.FileStore</code>.
149 </p>
150 <p>
151 This implements an abstraction of a random-access file.
152 This allows the higher layers to treat in-memory vs. on-disk vs. zip-file databases the same.
153 </p>
154
155 <!-- [close] { --></div></td></tr></table><!-- } --><!-- analytics --></body></html>