Debian Codegraph @

docs/storage.html

raw symbols SCIP
1 <?xml version="1.0" encoding="UTF-8"?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3 <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
4 <head>
5 <title>Redland RDF Application Framework - Storage Modules</title>
6 </head>
7 <body>
8
9 <h1 style="text-align:center">Redland RDF Application Framework - Storage Modules</h1>
10
11 <h2>Introduction</h2>
12
13 <p>Redland includes several modules that implement the
14 <a href="api/storage.html">storage API</a> and provide a variety of
15 different features and functionality. This document gives the
16 details of what each implementation module provides and
17 the storage options used.
18 </p>
19
20 <p>Store types:</p>
21
22 <ul>
23 <li><a href="#hashes">hashes</a></li>
24 <li><a href="#trees">trees</a></li>
25 <li><a href="#file">file</a></li>
26 <li><a href="#mysql">mysql</a></li>
27 <li><a href="#memory">memory</a></li>
28 <li><a href="#postgresql">postgresql</a></li>
29 <li><a href="#sqlite">sqlite</a></li>
30 <li><a href="#tstore">tstore</a></li>
31 <li><a href="#uri">uri</a></li>
32 </ul>
33
34
35 <h2><a name="hashes">Store 'hashes'</a></h2>
36
37 <p>This module is always present (cannot be removed) and provides
38 indexed storage using Redland <a href="api/storage.html">hashes</a>
39 to store various combinations of subject, predicate and object for
40 faster access. Context nodes are also stored in a hash when used.
41 The hashes may be in-memory (always available) or persistent via
42 Sleepycat/Berkeley DB (BDB) versions 2-4. It is the most mature and
43 primary persistent store and suitable for large models, tested in the
44 2-3 million range..</p>
45
46 <p>The main option requiring setting is the
47 <a name="hash-type"><code>hash-type</code></a>
48 which must be one of the supported Redland hashes.
49 Hash type <code>memory</code> is always available and if BDB
50 has been compiled in, <code>bdb</code> is also available.
51 Option <code>dir</code> can be used to set the destination
52 directory for the BDB files when used. Boolean option
53 <code>new</code> can be set to force creation or truncation
54 of a persistent hashed store. The storage
55 name must be given for hash type <code>bdb</code> since
56 it is used for a filename.
57 </p>
58
59 <p>The module provides optional contexts support enabled when
60 boolean storage option <code>contexts</code> is set. This
61 can be used with any hash type.</p>
62
63 <p>Examples:</p>
64 <pre>
65 /* A new BDB hashed persistent store in the current directory */
66 storage=librdf_new_storage(world, "hashes", "db1",
67 "new='yes',hash-type='bdb',dir='.'");
68
69 /* Hashed in-memory store */
70 storage=librdf_new_storage(world, "hashes", NULL,
71 "hash-type='memory'");
72
73 /* An existing BDB hashed persistent store in dir /somewhere */
74 storage=librdf_new_storage(world, "hashes", "dv2",
75 "hash-type='bdb',dir='/somewhere'");
76
77 /* An existing BDB hashed store with contexts */
78 storage=librdf_new_storage(world, "hashes", "db3",
79 "hash-type='bdb',contexts='yes'");
80 </pre>
81
82 <p>In Python:</p>
83 <pre>
84 from RDF import *
85 ...
86 # Create a new BDB store
87 storage = HashStorage("db4", options="new='yes',hash-type='bdb'")
88 </pre>
89
90 <p>In Perl:</p>
91 <pre>
92 use RDF::Redland;
93 ...
94 # Open an existing BDB store
95 $storage=new RDF::Redland::Storage("hashes", "db5",
96 "hash-type='bdb',dir='.'");
97 </pre>
98
99 <p>Summary:</p>
100
101 <ul>
102 <li>Persistent or in-memory</li>
103 <li>Suitable for larger models</li>
104 <li>Indexed</li>
105 <li>Large disk usage with BDB</li>
106 <li>Optional contexts (with option <code>contexts</code> set)</li>
107 </ul>
108
109
110 <h2><a name="trees">Store 'trees'</a></h2>
111
112 <p>This module is always present (cannot be removed) and provides
113 indexed storage using several balanced trees to store statements
114 for fast querying. This store is not persistent, but is suitable
115 for large models capable of fitting in main memory.</p>
116
117 <p>By default, the store is fully indexed providing good performance
118 for all types of queries. Options can be used to select only specific
119 indices to save memory and make insertion and deletion of statements
120 faster. The four boolean indexing options are <code>index-spo</code>,
121 <code>index-sop</code>, <code>index-ops</code> and <code>index-pso</code>.
122 An index is fast for triple patterns where the variables are on the right
123 hand side of the index ordering, e.g. the spo (subject, predicate, object)
124 index will be fast for (s p o) (s p ?o) and (s ?p ?o) queries. The ideal
125 index for every type of triple pattern is:
126 </p>
127 <dl>
128 <dt>Any index:</dt><dd>(s p o)<br/><br/></dd>
129 <dt>(s p o):</dt><dd>(s p ?o), (s ?p ?o)<br/><br/></dd>
130 <dt>(o p s):</dt><dd>(?s p o), (?s ?p o)<br/><br/></dd>
131 <dt>(s o p):</dt><dd>(s ?p o)<br/><br/></dd>
132 <dt>(p s o):</dt><dd>(?s p ?o)<br/><br/></dd>
133 </dl>
134
135 <p>
136 With full indexing the space used is roughly equivalent to the hashes
137 store. Insertion and deletion with 2 indices will be roughly twice as
138 fast as with 4 indices, etc. In the majority of cases, full indexing
139 will be fine and there is no need to worry about selecting the right
140 index for queries.
141 </p>
142
143 <p>Examples:</p>
144 <pre>
145 /* A fully indexed tree store */
146 storage=librdf_new_storage(world, "trees", NULL, NULL);
147
148 /* A tree store with only a (s p o) index */
149 storage=librdf_new_storage(world, "trees", NULL, "index-spo='yes'");
150
151 /* A tree store with only (s p o) and (o p s) indices
152 * (fast for everything but queries with predicate variables */
153 storage=librdf_new_storage(world, "trees", NULL,
154 "index-spo='yes',index-ops='yes'");
155
156 </pre>
157
158 <p>Summary:</p>
159
160 <ul>
161 <li>In-memory only</li>
162 <li>Suitable for larger models</li>
163 <li>Indexed, with selectable levels of indexing</li>
164 <li>No contexts</li>
165 <li>Significantly faster than hashes for most queries</li>
166 <li>Slower than hashes for exact statement search (librdf_model_contains_statement)</li>
167 </ul>
168
169
170
171
172 <h2><a name="memory">Store 'memory'</a></h2>
173
174 <p>This module is always present (cannot be removed) and provides a
175 simple and fast in-memory store with no persistence. It is
176 the default store if no store name is given to the storage
177 constructors.</p>
178
179 <p>The memory store is not suitable for large in-memory models since
180 it does not do any indexing. For that, use the
181 <a href="#hashes">hash indexed store</a> with
182 <a href="#hash-type">hash-type</a> of <code>memory</code>.</p>
183
184 <p>The module provides optional contexts support enabled when
185 boolean storage option <code>contexts</code> is set.</p>
186
187 <p>Examples:</p>
188 <pre>
189 /* Explicitly named memory storage */
190 storage=librdf_new_storage(world, "memory", NULL, NULL);
191
192 /* Default storage type, which is memory */
193 storage=librdf_new_storage(world, NULL, NULL, NULL);
194
195 /* In-memory store with contexts */
196 storage=librdf_new_storage(world, NULL, NULL, "contexts='yes'");
197 </pre>
198
199 <p>Summary:</p>
200
201 <ul>
202 <li>In-memory</li>
203 <li>Fast</li>
204 <li>Suitable for small models</li>
205 <li>No indexing</li>
206 <li>No persistence</li>
207 <li>Optional contexts (with option <code>contexts</code> set)</li>
208 </ul>
209
210
211 <h2><a name="file">Store 'file'</a></h2>
212
213 <p>This module provides an in-memory model (internally,
214 using a <a href="#memory">memory storage</a>) initialised from the
215 RDF/XML content in a file. The file is given as the storage name and
216 assumed to exist on opening. When a model or storage sync method
217 is called or the model or store is closed, a new file is created, the
218 old file renamed to a backup and the new file renamed to replace it.
219 This store was added in <a href="../RELEASE.html#rel0_9_15">Redland 0.9.15</a>
220 </p>
221
222 <p>There are no options for this store and contexts are not supported.</p>
223
224 <p>Example:</p>
225 <pre>
226 /* File based store from thing.rdf file */
227 storage=librdf_new_storage(world, "file", "thing.rdf", NULL);
228 </pre>
229
230 <p>Summary:</p>
231
232 <ul>
233 <li>In-memory</li>
234 <li>Suitable for small models</li>
235 <li>Simple local storage to content in RDF/XML</li>
236 <li>Not indexed</li>
237 <li>No contexts</li>
238 </ul>
239
240
241
242 <h2><a name="mysql">Store 'mysql'</a></h2>
243
244 <p>This module was written by
245 <a href="http://purl.org/net/morten/">Morten Frederiksen</a>
246 and is compiled in when MySQL 3 or 4 is available. This
247 store provides storage using the <a href="http://www.mysql.com/">MySQL</a>
248 open source database including contexts. It is a new store
249 added in
250 <a href="../RELEASE.html#rel0_9_15">Redland 0.9.15</a>
251 and is still under development. It has however been tested with
252 several million triples and deployed.</p>
253
254 <p>There are several options required with the mysql storage
255 in order to connect to the database. These are:</p>
256 <ul>
257 <li><code>host</code> for the database server hostname</li>
258 <li><code>port</code> for the database server port (defaults to the MySQL port 3306 if not given)</li>
259 <li><code>database</code> for the MySQL database name (not the storage name)</li>
260 <li><code>user</code> for the database server user name</li>
261 <li><code>password</code> for the database server password</li>
262 </ul>
263
264 <p>NOTE: Take care exposing the password as for example, program
265 arguments or environment variables. The
266 <a href="../utils/rdfproc.html">rdfproc</a>
267 utility can with help this by reading the password from standard
268 input. Inside programs, one way to prevent storing the password in a
269 string is to construct a Redland hash of the storage options such as
270 via <code>librdf_hash_from_string</code> and use
271 <code>librdf_new_storage_with_options</code> to create a storage.
272 The rdfproc utility source code demonstrates this.
273 </p>
274
275 <p>The storage name parameter given to the storage constructor
276 <code>librdf_new_storage</code> is used inside the mysql store to
277 allow multiple stores inside one MySQL database instance as
278 parameterised with the above optiosn.</p>
279
280 <p>If boolean option <code>new</code> is given, any existing MySQL
281 database named by the storage option <code>database</code>, say
282 <em>db</em> will be dropped and the appropriate new tables created.
283 The MySQL database <em>db</em> must already exist, such as made with
284 the MySQL <code>create database </code><em>db</em> command and the
285 appropriate privileges set so that the user and password work.
286 </p>
287
288 <p>If boolean option <code>reconnect</code> is given, MySQL
289 reconnection will be enabled so that if the database connection
290 is dropped, MySQL will attempt to reconnect.
291 </p>
292
293 <p>This store always provides contexts; the boolean storage option
294 <code>contexts</code> is not checked.</p>
295
296 <p>Examples:</p>
297 <pre>
298 /* A new MySQL store */
299 storage=librdf_new_storage(world, "mysql", "db1",
300 "new='yes',host='localhost',database='red',user='foo','password='bar'");
301
302 /* A different, existing MySQL store db2 in the same database as above */
303 storage=librdf_new_storage(world, "mysql", "db2",
304 "host='localhost',database='red',user='foo','password='bar'");
305
306 /* An existing MySQL store on a different database server */
307 storage=librdf_new_storage(world, "mysql", "db3",
308 "host='db.example.org',database='abc',user='baz','password='blah'");
309
310 /* Opening with an options hash */
311 options=librdf_new_hash(world, NULL);
312 librdf_hash_from_string(options,
313 "host='db.example.org',database='abc',user='baz'");
314 librdf_hash_put_strings(options, "password", user_password);
315 storage=librdf_new_storage_with_options(world, "mysql", "db4", options);
316 </pre>
317
318 <p>In PHP:</p>
319 <pre>
320 # An existing store
321 $storage=librdf_new_storage($world, 'mysql', 'db4',
322 "host='127.0.0.1',database='xyz',user='foo',password='blah'");
323
324 </pre>
325
326
327 <p>Summary:</p>
328
329 <ul>
330 <li>Persistent</li>
331 <li>Suitable for very large models</li>
332 <li>Indexed but not optimised</li>
333 <li>Smaller disk usage than BDB</li>
334 <li>Possibility of free text searching</li>
335 <li>Contexts always provided</li>
336 </ul>
337
338
339 <h2><a name="postgresql">Store 'postgresql'</a></h2>
340
341 <p>This module was written by Shi Wenzhong based on the MySQL store
342 written by Morten Frederiksen and is compiled in when PostgreSQL is
343 available. This store provides storage using the
344 <a href="http://www.postgresql.org/">PostgreSQL</a>
345 open source database including contexts. This store was added in
346 This <a href="../RELEASE.html#rel1_0_3">Redland 1.0.3</a>.</p>
347
348 <p>There are several options required with the postgresql storage
349 in order to connect to the database. These are:</p>
350 <ul>
351 <li><code>host</code> for the database server hostname</li>
352 <li><code>port</code> for the database server port (defaults to the Postgresql port 3306 if not given)</li>
353 <li><code>database</code> for the Postgresql database name (not the storage name)</li>
354 <li><code>user</code> for the database server user name</li>
355 <li><code>password</code> for the database server password</li>
356 <li><code>database</code> for the Postgresql database name (not the storage name)</li>
357 </ul>
358
359 <p>NOTE: Before Redland 1.0.5, the parameter <code>dbname</code> had
360 to be used instead of <code>database</code> for the Postgresql
361 database name</p>
362
363 <p>NOTE: Take care exposing the password as for example, program
364 arguments or environment variables. The
365 <a href="../utils/rdfproc.html">rdfproc</a>
366 utility can with help this by reading the password from standard
367 input. Inside programs, one way to prevent storing the password in a
368 string is to construct a Redland hash of the storage options such as
369 via <code>librdf_hash_from_string</code> and use
370 <code>librdf_new_storage_with_options</code> to create a storage.
371 The rdfproc utility source code demonstrates this.
372 </p>
373
374 <p>The storage name parameter given to the storage constructor
375 <code>librdf_new_storage</code> is used inside the postgresql store to
376 allow multiple stores inside one PostgreSQL database instance as
377 parameterised with the above optiosn.</p>
378
379 <p>If boolean option <code>new</code> is given, any existing PostgreSQL
380 database named by the storage option <code>database</code>, say
381 <em>db</em> will be dropped and the appropriate new tables created.
382 The PostgreSQL database <em>db</em> must already exist, such as made with
383 the PostgreSQL <code>create database </code><em>db</em> command and the
384 appropriate privileges set so that the user and password work.</p>
385
386 <p>This store always provides contexts; the boolean storage option
387 <code>contexts</code> is not checked.</p>
388
389 <p>Examples:</p>
390 <pre>
391 /* A new PostgreSQL store */
392 storage=librdf_new_storage(world, "postgresql", "db1",
393 "new='yes',host='localhost',database='red',user='foo','password='bar'");
394
395 /* A different, existing PostgreSQL store db2 in the same database as above */
396 storage=librdf_new_storage(world, "postgresql", "db2",
397 "host='localhost',database='red',user='foo','password='bar'");
398
399 /* An existing PostgreSQL store on a different database server */
400 storage=librdf_new_storage(world, "postgresql", "db3",
401 "host='db.example.org',database='abc',user='baz','password='blah'");
402
403 /* Opening with an options hash */
404 options=librdf_new_hash(world, NULL);
405 librdf_hash_from_string(options,
406 "host='db.example.org',database='abc',user='baz'");
407 librdf_hash_put_strings(options, "password", user_password);
408 storage=librdf_new_storage_with_options(world, "postgresql", "db4", options);
409 </pre>
410
411 <p>In PHP:</p>
412 <pre>
413 # An existing store
414 $storage=librdf_new_storage($world, 'postgresql', 'db4',
415 "host='127.0.0.1',database='xyz',user='foo',password='blah'");
416
417 </pre>
418
419
420 <p>Summary:</p>
421
422 <ul>
423 <li>Persistent</li>
424 <li>Suitable for very large models</li>
425 <li>Indexed but not optimised</li>
426 <li>Smaller disk usage than BDB</li>
427 <li>Contexts always provided</li>
428 </ul>
429
430
431 <h2><a name="sqlite">Store 'sqlite'</a></h2>
432
433 <p>This module provides storage via the
434 <a href="http://www.sqlite.org/">SQLite</a>
435 relational database when available and supports SQLite V2 and V3.
436 It was added in <a href="../RELEASE.html#rel1_0_0">Redland 1.0.0</a>
437 and is of beta quality. This store provides triples and contexts.
438 </p>
439
440 <p>The only option respected by this store is the
441 <code>new</code> one to create a new store, destroying any existing
442 store.
443 </p>
444
445 <p>Summary:</p>
446
447 <ul>
448 <li>Persistent</li>
449 <li>Suitable for small/medium models</li>
450 <li>Indexed but not optimized</li>
451 <li>Smaller disk usage than BDB</li>
452 <li>Contexts always provided</li>
453 </ul>
454
455
456 <h2><a name="tstore">Store 'tstore'</a></h2>
457
458 <p>This module provides storage via the
459 <a href="http://triplestore.aktors.org/">AKT Triplestore</a>
460 when available. It was added in
461 <a href="../RELEASE.html#rel0_9_15">Redland 0.9.15</a>
462 and is alpha quality - not complete or tested significantly (although
463 the AKT store itself is used in production). This store provides a
464 basic triple API but no redland contexts. The underlying RDQL
465 support and inference is not yet exposed in Redland but may be in
466 future.
467 </p>
468
469 <p>There are several options required with the tstore storage in
470 order to connect to the tstore database (which uses MySQL). These
471 are:</p>
472 <ul>
473 <li><code>host</code> for the database server hostname</li>
474 <li><code>port</code> for the database server port</li>
475 <li><code>database</code> for the database name (not the storage name)</li>
476 <li><code>user</code> for the database server user name</li>
477 <li><code>password</code> for the database server password</li>
478 </ul>
479
480 <p>NOTE: Take care exposing the password as for example, program
481 arguments or environment variables. The
482 <a href="../utils/rdfproc.html">rdfproc</a>
483 utility can with help this by reading the password from standard
484 input. Inside programs, one way to prevent storing the password in a
485 string is to construct a Redland hash of the storage options such as
486 via <code>librdf_hash_from_string</code> and use
487 <code>librdf_new_storage_with_options</code> to create a storage.
488 The rdfproc utility source code demonstrates this.
489 </p>
490
491
492 <p>Summary:</p>
493
494 <ul>
495 <li>Persistent</li>
496 <li>Suitable for very large models</li>
497 <li>Indexed and optimised by the AKT project</li>
498 <li>No Redland contexts</li>
499 <li>Alpha quality</li>
500 </ul>
501
502
503 <h2><a name="uri">Store 'uri'</a></h2>
504
505 <p>This module provides an in-memory model (internally,
506 using a <a href="#memory">memory storage</a>) initialised from the
507 RDF/XML content in a URI. The URI is given as the storage name and
508 on closing, the model is destroyed. This is a new store added in
509 <a href="../RELEASE.html#rel0_9_15">Redland 0.9.15</a>
510 and is still under development. In future it may be
511 extended to allow saving the store to the URI.
512 </p>
513
514 <p>There are no options for this store and contexts are not supported.</p>
515
516 <p>Example:</p>
517 <pre>
518 /* Read URI content into a store */
519 storage=librdf_new_storage(world, "uri",
520 "http://example.org/content.rdf", NULL);
521 </pre>
522
523
524 <p>Summary:</p>
525
526 <ul>
527 <li>In-memory</li>
528 <li>Suitable for small models</li>
529 <li>Easy access to web content in RDF/XML</li>
530 <li>Not indexed</li>
531 <li>No contexts</li>
532 </ul>
533
534
535
536 <hr />
537
538 <p>Copyright 2004-2007 <a href="http://purl.org/net/dajobe/">Dave Beckett</a>, Copyright 2004 <a href="http://www.bristol.ac.uk/">University of Bristol</a></p>
539
540 </body>
541 </html>