diff options
author | David Barksdale <amatus@amat.us> | 2018-01-14 01:03:12 -0600 |
---|---|---|
committer | David Barksdale <amatus@amat.us> | 2018-01-14 01:03:12 -0600 |
commit | 54323fd662beaa9004bdfcf68bac78d613d90c74 (patch) | |
tree | cd494f25e33157105793cdd943b3cc17e849e5ac /src/datastore | |
parent | 93ee5f80204b1df7e495fc95bbc2270c11da9b6d (diff) | |
download | gnunet-54323fd662beaa9004bdfcf68bac78d613d90c74.tar.gz gnunet-54323fd662beaa9004bdfcf68bac78d613d90c74.zip |
SQLite doesn't constant fold
Diffstat (limited to 'src/datastore')
-rw-r--r-- | src/datastore/plugin_datastore_sqlite.c | 82 |
1 files changed, 66 insertions, 16 deletions
diff --git a/src/datastore/plugin_datastore_sqlite.c b/src/datastore/plugin_datastore_sqlite.c index cc56f5959..d51fd3e01 100644 --- a/src/datastore/plugin_datastore_sqlite.c +++ b/src/datastore/plugin_datastore_sqlite.c | |||
@@ -135,7 +135,7 @@ struct Plugin | |||
135 | /** | 135 | /** |
136 | * Precompiled SQL for selection | 136 | * Precompiled SQL for selection |
137 | */ | 137 | */ |
138 | sqlite3_stmt *get; | 138 | sqlite3_stmt *get[8]; |
139 | 139 | ||
140 | /** | 140 | /** |
141 | * Should the database be dropped on shutdown? | 141 | * Should the database be dropped on shutdown? |
@@ -386,12 +386,63 @@ database_setup (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
386 | (SQLITE_OK != | 386 | (SQLITE_OK != |
387 | sq_prepare (plugin->dbh, | 387 | sq_prepare (plugin->dbh, |
388 | "SELECT " RESULT_COLUMNS " FROM gn091 " | 388 | "SELECT " RESULT_COLUMNS " FROM gn091 " |
389 | "WHERE _ROWID_ >= ? AND " | 389 | "WHERE _ROWID_ >= ?1 " |
390 | "(rvalue >= ? OR 0 = ?) AND " | 390 | "ORDER BY _ROWID_ ASC LIMIT 1", |
391 | "(hash = ? OR 0 = ?) AND " | 391 | &plugin->get[0])) || |
392 | "(type = ? OR 0 = ?) " | 392 | (SQLITE_OK != |
393 | sq_prepare (plugin->dbh, | ||
394 | "SELECT " RESULT_COLUMNS " FROM gn091 " | ||
395 | "WHERE _ROWID_ >= ?1 AND " | ||
396 | "type = ?4 " | ||
397 | "ORDER BY _ROWID_ ASC LIMIT 1", | ||
398 | &plugin->get[1])) || | ||
399 | (SQLITE_OK != | ||
400 | sq_prepare (plugin->dbh, | ||
401 | "SELECT " RESULT_COLUMNS " FROM gn091 " | ||
402 | "WHERE _ROWID_ >= ?1 AND " | ||
403 | "hash = ?3 " | ||
404 | "ORDER BY _ROWID_ ASC LIMIT 1", | ||
405 | &plugin->get[2])) || | ||
406 | (SQLITE_OK != | ||
407 | sq_prepare (plugin->dbh, | ||
408 | "SELECT " RESULT_COLUMNS " FROM gn091 " | ||
409 | "WHERE _ROWID_ >= ?1 AND " | ||
410 | "hash = ?3 AND " | ||
411 | "type = ?4 " | ||
412 | "ORDER BY _ROWID_ ASC LIMIT 1", | ||
413 | &plugin->get[3])) || | ||
414 | (SQLITE_OK != | ||
415 | sq_prepare (plugin->dbh, | ||
416 | "SELECT " RESULT_COLUMNS " FROM gn091 " | ||
417 | "WHERE _ROWID_ >= ?1 AND " | ||
418 | "rvalue >= ?2 " | ||
419 | "ORDER BY _ROWID_ ASC LIMIT 1", | ||
420 | &plugin->get[4])) || | ||
421 | (SQLITE_OK != | ||
422 | sq_prepare (plugin->dbh, | ||
423 | "SELECT " RESULT_COLUMNS " FROM gn091 " | ||
424 | "WHERE _ROWID_ >= ?1 AND " | ||
425 | "rvalue >= ?2 AND " | ||
426 | "type = ?4 " | ||
393 | "ORDER BY _ROWID_ ASC LIMIT 1", | 427 | "ORDER BY _ROWID_ ASC LIMIT 1", |
394 | &plugin->get)) || | 428 | &plugin->get[5])) || |
429 | (SQLITE_OK != | ||
430 | sq_prepare (plugin->dbh, | ||
431 | "SELECT " RESULT_COLUMNS " FROM gn091 " | ||
432 | "WHERE _ROWID_ >= ?1 AND " | ||
433 | "rvalue >= ?2 AND " | ||
434 | "hash = ?3 " | ||
435 | "ORDER BY _ROWID_ ASC LIMIT 1", | ||
436 | &plugin->get[6])) || | ||
437 | (SQLITE_OK != | ||
438 | sq_prepare (plugin->dbh, | ||
439 | "SELECT " RESULT_COLUMNS " FROM gn091 " | ||
440 | "WHERE _ROWID_ >= ?1 AND " | ||
441 | "rvalue >= ?2 AND " | ||
442 | "hash = ?3 AND " | ||
443 | "type = ?4 " | ||
444 | "ORDER BY _ROWID_ ASC LIMIT 1", | ||
445 | &plugin->get[7])) || | ||
395 | (SQLITE_OK != | 446 | (SQLITE_OK != |
396 | sq_prepare (plugin->dbh, | 447 | sq_prepare (plugin->dbh, |
397 | "DELETE FROM gn091 WHERE _ROWID_ = ?", | 448 | "DELETE FROM gn091 WHERE _ROWID_ = ?", |
@@ -445,8 +496,9 @@ database_shutdown (struct Plugin *plugin) | |||
445 | sqlite3_finalize (plugin->selZeroAnon); | 496 | sqlite3_finalize (plugin->selZeroAnon); |
446 | if (NULL != plugin->insertContent) | 497 | if (NULL != plugin->insertContent) |
447 | sqlite3_finalize (plugin->insertContent); | 498 | sqlite3_finalize (plugin->insertContent); |
448 | if (NULL != plugin->get) | 499 | for (int i = 0; i < 8; ++i) |
449 | sqlite3_finalize (plugin->get); | 500 | if (NULL != plugin->get[i]) |
501 | sqlite3_finalize (plugin->get[i]); | ||
450 | result = sqlite3_close (plugin->dbh); | 502 | result = sqlite3_close (plugin->dbh); |
451 | #if SQLITE_VERSION_NUMBER >= 3007000 | 503 | #if SQLITE_VERSION_NUMBER >= 3007000 |
452 | if (result == SQLITE_BUSY) | 504 | if (result == SQLITE_BUSY) |
@@ -843,18 +895,16 @@ sqlite_plugin_get_key (void *cls, | |||
843 | { | 895 | { |
844 | struct Plugin *plugin = cls; | 896 | struct Plugin *plugin = cls; |
845 | uint64_t rvalue; | 897 | uint64_t rvalue; |
846 | uint16_t use_rvalue = random; | 898 | int use_rvalue = random; |
847 | uint32_t type32 = (uint32_t) type; | 899 | uint32_t type32 = (uint32_t) type; |
848 | uint16_t use_type = GNUNET_BLOCK_TYPE_ANY != type; | 900 | int use_type = GNUNET_BLOCK_TYPE_ANY != type; |
849 | uint16_t use_key = NULL != key; | 901 | int use_key = NULL != key; |
902 | sqlite3_stmt *stmt = plugin->get[use_rvalue * 4 + use_key * 2 + use_type]; | ||
850 | struct GNUNET_SQ_QueryParam params[] = { | 903 | struct GNUNET_SQ_QueryParam params[] = { |
851 | GNUNET_SQ_query_param_uint64 (&next_uid), | 904 | GNUNET_SQ_query_param_uint64 (&next_uid), |
852 | GNUNET_SQ_query_param_uint64 (&rvalue), | 905 | GNUNET_SQ_query_param_uint64 (&rvalue), |
853 | GNUNET_SQ_query_param_uint16 (&use_rvalue), | ||
854 | GNUNET_SQ_query_param_auto_from_type (key), | 906 | GNUNET_SQ_query_param_auto_from_type (key), |
855 | GNUNET_SQ_query_param_uint16 (&use_key), | ||
856 | GNUNET_SQ_query_param_uint32 (&type32), | 907 | GNUNET_SQ_query_param_uint32 (&type32), |
857 | GNUNET_SQ_query_param_uint16 (&use_type), | ||
858 | GNUNET_SQ_query_param_end | 908 | GNUNET_SQ_query_param_end |
859 | }; | 909 | }; |
860 | 910 | ||
@@ -868,14 +918,14 @@ sqlite_plugin_get_key (void *cls, | |||
868 | rvalue = 0; | 918 | rvalue = 0; |
869 | 919 | ||
870 | if (GNUNET_OK != | 920 | if (GNUNET_OK != |
871 | GNUNET_SQ_bind (plugin->get, | 921 | GNUNET_SQ_bind (stmt, |
872 | params)) | 922 | params)) |
873 | { | 923 | { |
874 | proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); | 924 | proc (proc_cls, NULL, 0, NULL, 0, 0, 0, 0, GNUNET_TIME_UNIT_ZERO_ABS, 0); |
875 | return; | 925 | return; |
876 | } | 926 | } |
877 | execute_get (plugin, | 927 | execute_get (plugin, |
878 | plugin->get, | 928 | stmt, |
879 | proc, | 929 | proc, |
880 | proc_cls); | 930 | proc_cls); |
881 | } | 931 | } |