aboutsummaryrefslogtreecommitdiff
path: root/src/datastore/plugin_datastore_postgres.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-06-10 15:39:28 +0000
committerChristian Grothoff <christian@grothoff.org>2011-06-10 15:39:28 +0000
commit49649b2ac771f8e01c3439a8d9d1567b1a5e4fc8 (patch)
treee7f65e618e3ea4700af1e212b802e484216b8d9c /src/datastore/plugin_datastore_postgres.c
parent76e8462020b7ed63330fd0f115307ba76806a0a0 (diff)
downloadgnunet-49649b2ac771f8e01c3439a8d9d1567b1a5e4fc8.tar.gz
gnunet-49649b2ac771f8e01c3439a8d9d1567b1a5e4fc8.zip
fixing datastore schema for future change for improved performance
Diffstat (limited to 'src/datastore/plugin_datastore_postgres.c')
-rw-r--r--src/datastore/plugin_datastore_postgres.c24
1 files changed, 16 insertions, 8 deletions
diff --git a/src/datastore/plugin_datastore_postgres.c b/src/datastore/plugin_datastore_postgres.c
index 30a6c20da..9d60100cf 100644
--- a/src/datastore/plugin_datastore_postgres.c
+++ b/src/datastore/plugin_datastore_postgres.c
@@ -190,6 +190,7 @@ init_connection (struct Plugin *plugin)
190 " prio INTEGER NOT NULL DEFAULT 0," 190 " prio INTEGER NOT NULL DEFAULT 0,"
191 " anonLevel INTEGER NOT NULL DEFAULT 0," 191 " anonLevel INTEGER NOT NULL DEFAULT 0,"
192 " expire BIGINT NOT NULL DEFAULT 0," 192 " expire BIGINT NOT NULL DEFAULT 0,"
193 " rvalue BIGINT NOT NULL DEFAULT 0,"
193 " hash BYTEA NOT NULL DEFAULT ''," 194 " hash BYTEA NOT NULL DEFAULT '',"
194 " vhash BYTEA NOT NULL DEFAULT ''," 195 " vhash BYTEA NOT NULL DEFAULT '',"
195 " value BYTEA NOT NULL DEFAULT '')" "WITH OIDS"); 196 " value BYTEA NOT NULL DEFAULT '')" "WITH OIDS");
@@ -218,14 +219,18 @@ init_connection (struct Plugin *plugin)
218 || (GNUNET_OK != 219 || (GNUNET_OK !=
219 pq_exec (plugin, "CREATE INDEX idx_expire ON gn090 (expire)", __LINE__)) 220 pq_exec (plugin, "CREATE INDEX idx_expire ON gn090 (expire)", __LINE__))
220 || (GNUNET_OK != 221 || (GNUNET_OK !=
221 pq_exec (plugin, "CREATE INDEX idx_comb3 ON gn090 (prio,anonLevel)", 222 pq_exec (plugin, "CREATE INDEX idx_prio_anon ON gn090 (prio,anonLevel)",
222 __LINE__)) 223 __LINE__))
223 || (GNUNET_OK != 224 || (GNUNET_OK !=
224 pq_exec 225 pq_exec
225 (plugin, "CREATE INDEX idx_comb4 ON gn090 (prio,hash,anonLevel)", 226 (plugin, "CREATE INDEX idx_prio_hash_anon ON gn090 (prio,hash,anonLevel)",
226 __LINE__)) 227 __LINE__))
227 || (GNUNET_OK != 228 || (GNUNET_OK !=
228 pq_exec (plugin, "CREATE INDEX idx_comb7 ON gn090 (expire,hash)", 229 pq_exec
230 (plugin, "CREATE INDEX idx_repl_rvalue ON gn090 (repl,rvalue)",
231 __LINE__))
232 || (GNUNET_OK !=
233 pq_exec (plugin, "CREATE INDEX idx_expire_hash ON gn090 (expire,hash)",
229 __LINE__))) 234 __LINE__)))
230 { 235 {
231 PQclear (ret); 236 PQclear (ret);
@@ -305,9 +310,9 @@ init_connection (struct Plugin *plugin)
305 (GNUNET_OK != 310 (GNUNET_OK !=
306 pq_prepare (plugin, 311 pq_prepare (plugin,
307 "put", 312 "put",
308 "INSERT INTO gn090 (repl, type, prio, anonLevel, expire, hash, vhash, value) " 313 "INSERT INTO gn090 (repl, type, prio, anonLevel, expire, rvalue, hash, vhash, value) "
309 "VALUES ($1, $2, $3, $4, $5, $6, $7, $8)", 314 "VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)",
310 8, 315 9,
311 __LINE__)) || 316 __LINE__)) ||
312 (GNUNET_OK != 317 (GNUNET_OK !=
313 pq_prepare (plugin, 318 pq_prepare (plugin,
@@ -472,12 +477,14 @@ postgres_plugin_put (void *cls,
472 uint32_t banon = htonl (anonymity); 477 uint32_t banon = htonl (anonymity);
473 uint32_t brepl = htonl (replication); 478 uint32_t brepl = htonl (replication);
474 uint64_t bexpi = GNUNET_TIME_absolute_hton (expiration).abs_value__; 479 uint64_t bexpi = GNUNET_TIME_absolute_hton (expiration).abs_value__;
480 uint64_t rvalue = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, UINT64_MAX);
475 const char *paramValues[] = { 481 const char *paramValues[] = {
476 (const char *) &brepl, 482 (const char *) &brepl,
477 (const char *) &btype, 483 (const char *) &btype,
478 (const char *) &bprio, 484 (const char *) &bprio,
479 (const char *) &banon, 485 (const char *) &banon,
480 (const char *) &bexpi, 486 (const char *) &bexpi,
487 (const char *) &rvalue,
481 (const char *) key, 488 (const char *) key,
482 (const char *) &vhash, 489 (const char *) &vhash,
483 (const char *) data 490 (const char *) data
@@ -488,15 +495,16 @@ postgres_plugin_put (void *cls,
488 sizeof (bprio), 495 sizeof (bprio),
489 sizeof (banon), 496 sizeof (banon),
490 sizeof (bexpi), 497 sizeof (bexpi),
498 sizeof (rvalue),
491 sizeof (GNUNET_HashCode), 499 sizeof (GNUNET_HashCode),
492 sizeof (GNUNET_HashCode), 500 sizeof (GNUNET_HashCode),
493 size 501 size
494 }; 502 };
495 const int paramFormats[] = { 1, 1, 1, 1, 1, 1, 1, 1 }; 503 const int paramFormats[] = { 1, 1, 1, 1, 1, 1, 1, 1, 1 };
496 504
497 GNUNET_CRYPTO_hash (data, size, &vhash); 505 GNUNET_CRYPTO_hash (data, size, &vhash);
498 ret = PQexecPrepared (plugin->dbh, 506 ret = PQexecPrepared (plugin->dbh,
499 "put", 8, paramValues, paramLengths, paramFormats, 1); 507 "put", 9, paramValues, paramLengths, paramFormats, 1);
500 if (GNUNET_OK != check_result (plugin, ret, 508 if (GNUNET_OK != check_result (plugin, ret,
501 PGRES_COMMAND_OK, 509 PGRES_COMMAND_OK,
502 "PQexecPrepared", "put", __LINE__)) 510 "PQexecPrepared", "put", __LINE__))