diff options
author | Christian Grothoff <christian@grothoff.org> | 2018-04-30 16:22:47 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2018-04-30 16:22:47 +0200 |
commit | 4b5c6cceb0284774a161d426b606f40644abfb4c (patch) | |
tree | f2f63b8df7e6bb329ef25eca97e27d4deac55b69 /src/namestore/plugin_namestore_postgres.c | |
parent | c66809401efc16f2606db7e2c7b7ca8def8be14e (diff) | |
download | gnunet-4b5c6cceb0284774a161d426b606f40644abfb4c.tar.gz gnunet-4b5c6cceb0284774a161d426b606f40644abfb4c.zip |
eliminate use of OFFSET in namestore DB queries
Diffstat (limited to 'src/namestore/plugin_namestore_postgres.c')
-rw-r--r-- | src/namestore/plugin_namestore_postgres.c | 47 |
1 files changed, 26 insertions, 21 deletions
diff --git a/src/namestore/plugin_namestore_postgres.c b/src/namestore/plugin_namestore_postgres.c index 4a24ddf88..42bc9e4c9 100644 --- a/src/namestore/plugin_namestore_postgres.c +++ b/src/namestore/plugin_namestore_postgres.c | |||
@@ -65,7 +65,8 @@ static int | |||
65 | database_setup (struct Plugin *plugin) | 65 | database_setup (struct Plugin *plugin) |
66 | { | 66 | { |
67 | struct GNUNET_PQ_ExecuteStatement es_temporary = | 67 | struct GNUNET_PQ_ExecuteStatement es_temporary = |
68 | GNUNET_PQ_make_execute ("CREATE TEMPORARY TABLE IF NOT EXISTS ns097records (" | 68 | GNUNET_PQ_make_execute ("CREATE TEMPORARY TABLE IF NOT EXISTS ns098records (" |
69 | " seq BIGSERIAL PRIMARY KEY," | ||
69 | " zone_private_key BYTEA NOT NULL DEFAULT ''," | 70 | " zone_private_key BYTEA NOT NULL DEFAULT ''," |
70 | " pkey BYTEA DEFAULT ''," | 71 | " pkey BYTEA DEFAULT ''," |
71 | " rvalue BYTEA NOT NULL DEFAULT ''," | 72 | " rvalue BYTEA NOT NULL DEFAULT ''," |
@@ -75,7 +76,8 @@ database_setup (struct Plugin *plugin) | |||
75 | ")" | 76 | ")" |
76 | "WITH OIDS"); | 77 | "WITH OIDS"); |
77 | struct GNUNET_PQ_ExecuteStatement es_default = | 78 | struct GNUNET_PQ_ExecuteStatement es_default = |
78 | GNUNET_PQ_make_execute ("CREATE TABLE IF NOT EXISTS ns097records (" | 79 | GNUNET_PQ_make_execute ("CREATE TABLE IF NOT EXISTS ns098records (" |
80 | " seq SERIAL PRIMARY KEY," | ||
79 | " zone_private_key BYTEA NOT NULL DEFAULT ''," | 81 | " zone_private_key BYTEA NOT NULL DEFAULT ''," |
80 | " pkey BYTEA DEFAULT ''," | 82 | " pkey BYTEA DEFAULT ''," |
81 | " rvalue BYTEA NOT NULL DEFAULT ''," | 83 | " rvalue BYTEA NOT NULL DEFAULT ''," |
@@ -125,13 +127,11 @@ database_setup (struct Plugin *plugin) | |||
125 | struct GNUNET_PQ_ExecuteStatement es[] = { | 127 | struct GNUNET_PQ_ExecuteStatement es[] = { |
126 | *cr, | 128 | *cr, |
127 | GNUNET_PQ_make_try_execute ("CREATE INDEX IF NOT EXISTS ir_pkey_reverse " | 129 | GNUNET_PQ_make_try_execute ("CREATE INDEX IF NOT EXISTS ir_pkey_reverse " |
128 | "ON ns097records (zone_private_key,pkey)"), | 130 | "ON ns098records (zone_private_key,pkey)"), |
129 | GNUNET_PQ_make_try_execute ("CREATE INDEX IF NOT EXISTS ir_pkey_iter " | 131 | GNUNET_PQ_make_try_execute ("CREATE INDEX IF NOT EXISTS ir_pkey_iter " |
130 | "ON ns097records (zone_private_key,rvalue)"), | 132 | "ON ns098records (zone_private_key,seq)"), |
131 | GNUNET_PQ_make_try_execute ("CREATE INDEX IF NOT EXISTS it_iter " | ||
132 | "ON ns097records (rvalue)"), | ||
133 | GNUNET_PQ_make_try_execute ("CREATE INDEX IF NOT EXISTS ir_label " | 133 | GNUNET_PQ_make_try_execute ("CREATE INDEX IF NOT EXISTS ir_label " |
134 | "ON ns097records (label)"), | 134 | "ON ns098records (label)"), |
135 | GNUNET_PQ_EXECUTE_STATEMENT_END | 135 | GNUNET_PQ_EXECUTE_STATEMENT_END |
136 | }; | 136 | }; |
137 | 137 | ||
@@ -148,28 +148,28 @@ database_setup (struct Plugin *plugin) | |||
148 | { | 148 | { |
149 | struct GNUNET_PQ_PreparedStatement ps[] = { | 149 | struct GNUNET_PQ_PreparedStatement ps[] = { |
150 | GNUNET_PQ_make_prepare ("store_records", | 150 | GNUNET_PQ_make_prepare ("store_records", |
151 | "INSERT INTO ns097records (zone_private_key, pkey, rvalue, record_count, record_data, label) VALUES " | 151 | "INSERT INTO ns098records (zone_private_key, pkey, rvalue, record_count, record_data, label) VALUES " |
152 | "($1, $2, $3, $4, $5, $6)", | 152 | "($1, $2, $3, $4, $5, $6)", |
153 | 6), | 153 | 6), |
154 | GNUNET_PQ_make_prepare ("delete_records", | 154 | GNUNET_PQ_make_prepare ("delete_records", |
155 | "DELETE FROM ns097records " | 155 | "DELETE FROM ns098records " |
156 | "WHERE zone_private_key=$1 AND label=$2", | 156 | "WHERE zone_private_key=$1 AND label=$2", |
157 | 2), | 157 | 2), |
158 | GNUNET_PQ_make_prepare ("zone_to_name", | 158 | GNUNET_PQ_make_prepare ("zone_to_name", |
159 | "SELECT record_count,record_data,label FROM ns097records" | 159 | "SELECT seq,record_count,record_data,label FROM ns098records" |
160 | " WHERE zone_private_key=$1 AND pkey=$2", | 160 | " WHERE zone_private_key=$1 AND pkey=$2", |
161 | 2), | 161 | 2), |
162 | GNUNET_PQ_make_prepare ("iterate_zone", | 162 | GNUNET_PQ_make_prepare ("iterate_zone", |
163 | "SELECT record_count,record_data,label FROM ns097records " | 163 | "SELECT seq,record_count,record_data,label FROM ns098records " |
164 | "WHERE zone_private_key=$1 ORDER BY rvalue OFFSET $2 LIMIT $3", | 164 | "WHERE zone_private_key=$1 AND seq > $2 ORDER BY seq ASC LIMIT $3", |
165 | 3), | 165 | 3), |
166 | GNUNET_PQ_make_prepare ("iterate_all_zones", | 166 | GNUNET_PQ_make_prepare ("iterate_all_zones", |
167 | "SELECT record_count,record_data,label,zone_private_key" | 167 | "SELECT seq,record_count,record_data,label,zone_private_key" |
168 | " FROM ns097records ORDER BY rvalue OFFSET $1 LIMIT $2", | 168 | " FROM ns098records WHERE seq > $1 ORDER BY seq ASC LIMIT $2", |
169 | 2), | 169 | 2), |
170 | GNUNET_PQ_make_prepare ("lookup_label", | 170 | GNUNET_PQ_make_prepare ("lookup_label", |
171 | "SELECT record_count,record_data,label " | 171 | "SELECT seq,record_count,record_data,label " |
172 | "FROM ns097records WHERE zone_private_key=$1 AND label=$2", | 172 | "FROM ns098records WHERE zone_private_key=$1 AND label=$2", |
173 | 2), | 173 | 2), |
174 | GNUNET_PQ_PREPARED_STATEMENT_END | 174 | GNUNET_PQ_PREPARED_STATEMENT_END |
175 | }; | 175 | }; |
@@ -224,7 +224,8 @@ namestore_postgres_store_records (void *cls, | |||
224 | } | 224 | } |
225 | rvalue = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, | 225 | rvalue = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, |
226 | UINT64_MAX); | 226 | UINT64_MAX); |
227 | data_size = GNUNET_GNSRECORD_records_get_size (rd_count, rd); | 227 | data_size = GNUNET_GNSRECORD_records_get_size (rd_count, |
228 | rd); | ||
228 | if (data_size > 64 * 65536) | 229 | if (data_size > 64 * 65536) |
229 | { | 230 | { |
230 | GNUNET_break (0); | 231 | GNUNET_break (0); |
@@ -312,12 +313,14 @@ parse_result_call_iterator (void *cls, | |||
312 | return; /* no need to do more work */ | 313 | return; /* no need to do more work */ |
313 | for (unsigned int i=0;i<num_results;i++) | 314 | for (unsigned int i=0;i<num_results;i++) |
314 | { | 315 | { |
316 | uint64_t serial; | ||
315 | void *data; | 317 | void *data; |
316 | size_t data_size; | 318 | size_t data_size; |
317 | uint32_t record_count; | 319 | uint32_t record_count; |
318 | char *label; | 320 | char *label; |
319 | struct GNUNET_CRYPTO_EcdsaPrivateKey zk; | 321 | struct GNUNET_CRYPTO_EcdsaPrivateKey zk; |
320 | struct GNUNET_PQ_ResultSpec rs_with_zone[] = { | 322 | struct GNUNET_PQ_ResultSpec rs_with_zone[] = { |
323 | GNUNET_PQ_result_spec_uint64 ("seq", &serial), | ||
321 | GNUNET_PQ_result_spec_uint32 ("record_count", &record_count), | 324 | GNUNET_PQ_result_spec_uint32 ("record_count", &record_count), |
322 | GNUNET_PQ_result_spec_variable_size ("record_data", &data, &data_size), | 325 | GNUNET_PQ_result_spec_variable_size ("record_data", &data, &data_size), |
323 | GNUNET_PQ_result_spec_string ("label", &label), | 326 | GNUNET_PQ_result_spec_string ("label", &label), |
@@ -325,6 +328,7 @@ parse_result_call_iterator (void *cls, | |||
325 | GNUNET_PQ_result_spec_end | 328 | GNUNET_PQ_result_spec_end |
326 | }; | 329 | }; |
327 | struct GNUNET_PQ_ResultSpec rs_without_zone[] = { | 330 | struct GNUNET_PQ_ResultSpec rs_without_zone[] = { |
331 | GNUNET_PQ_result_spec_uint64 ("seq", &serial), | ||
328 | GNUNET_PQ_result_spec_uint32 ("record_count", &record_count), | 332 | GNUNET_PQ_result_spec_uint32 ("record_count", &record_count), |
329 | GNUNET_PQ_result_spec_variable_size ("record_data", &data, &data_size), | 333 | GNUNET_PQ_result_spec_variable_size ("record_data", &data, &data_size), |
330 | GNUNET_PQ_result_spec_string ("label", &label), | 334 | GNUNET_PQ_result_spec_string ("label", &label), |
@@ -365,6 +369,7 @@ parse_result_call_iterator (void *cls, | |||
365 | return; | 369 | return; |
366 | } | 370 | } |
367 | pc->iter (pc->iter_cls, | 371 | pc->iter (pc->iter_cls, |
372 | serial, | ||
368 | (NULL == pc->zone_key) ? &zk : pc->zone_key, | 373 | (NULL == pc->zone_key) ? &zk : pc->zone_key, |
369 | label, | 374 | label, |
370 | record_count, | 375 | record_count, |
@@ -422,7 +427,7 @@ namestore_postgres_lookup_records (void *cls, | |||
422 | * | 427 | * |
423 | * @param cls closure (internal context for the plugin) | 428 | * @param cls closure (internal context for the plugin) |
424 | * @param zone hash of public key of the zone, NULL to iterate over all zones | 429 | * @param zone hash of public key of the zone, NULL to iterate over all zones |
425 | * @param offset offset in the list of all matching records | 430 | * @param serial serial number to exclude in the list of all matching records |
426 | * @param limit maximum number of results to fetch | 431 | * @param limit maximum number of results to fetch |
427 | * @param iter function to call with the result | 432 | * @param iter function to call with the result |
428 | * @param iter_cls closure for @a iter | 433 | * @param iter_cls closure for @a iter |
@@ -431,7 +436,7 @@ namestore_postgres_lookup_records (void *cls, | |||
431 | static int | 436 | static int |
432 | namestore_postgres_iterate_records (void *cls, | 437 | namestore_postgres_iterate_records (void *cls, |
433 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, | 438 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, |
434 | uint64_t offset, | 439 | uint64_t serial, |
435 | uint64_t limit, | 440 | uint64_t limit, |
436 | GNUNET_NAMESTORE_RecordIterator iter, | 441 | GNUNET_NAMESTORE_RecordIterator iter, |
437 | void *iter_cls) | 442 | void *iter_cls) |
@@ -447,7 +452,7 @@ namestore_postgres_iterate_records (void *cls, | |||
447 | if (NULL == zone) | 452 | if (NULL == zone) |
448 | { | 453 | { |
449 | struct GNUNET_PQ_QueryParam params_without_zone[] = { | 454 | struct GNUNET_PQ_QueryParam params_without_zone[] = { |
450 | GNUNET_PQ_query_param_uint64 (&offset), | 455 | GNUNET_PQ_query_param_uint64 (&serial), |
451 | GNUNET_PQ_query_param_uint64 (&limit), | 456 | GNUNET_PQ_query_param_uint64 (&limit), |
452 | GNUNET_PQ_query_param_end | 457 | GNUNET_PQ_query_param_end |
453 | }; | 458 | }; |
@@ -462,7 +467,7 @@ namestore_postgres_iterate_records (void *cls, | |||
462 | { | 467 | { |
463 | struct GNUNET_PQ_QueryParam params_with_zone[] = { | 468 | struct GNUNET_PQ_QueryParam params_with_zone[] = { |
464 | GNUNET_PQ_query_param_auto_from_type (zone), | 469 | GNUNET_PQ_query_param_auto_from_type (zone), |
465 | GNUNET_PQ_query_param_uint64 (&offset), | 470 | GNUNET_PQ_query_param_uint64 (&serial), |
466 | GNUNET_PQ_query_param_uint64 (&limit), | 471 | GNUNET_PQ_query_param_uint64 (&limit), |
467 | GNUNET_PQ_query_param_end | 472 | GNUNET_PQ_query_param_end |
468 | }; | 473 | }; |