From 3f7aa8c6e4a718f1ce5a5b9d98f0817e067850d9 Mon Sep 17 00:00:00 2001 From: Lorenzo Delgado Date: Mon, 5 Sep 2022 15:18:47 +0200 Subject: [PATCH] fix(waku-store): added an index to improve messages query time --- waku/v2/node/storage/message/waku_message_store_queries.nim | 2 +- waku/v2/node/storage/migration/migration_types.nim | 2 +- .../migrations_scripts/message/00005_updateIndex.up.sql | 3 +++ 3 files changed, 5 insertions(+), 2 deletions(-) create mode 100644 waku/v2/node/storage/migration/migrations_scripts/message/00005_updateIndex.up.sql diff --git a/waku/v2/node/storage/message/waku_message_store_queries.nim b/waku/v2/node/storage/message/waku_message_store_queries.nim index a97a46588..e964dfb2a 100644 --- a/waku/v2/node/storage/message/waku_message_store_queries.nim +++ b/waku/v2/node/storage/message/waku_message_store_queries.nim @@ -76,7 +76,7 @@ proc createTable*(db: SqliteDatabase): DatabaseResult[void] {.inline.} = ## Create index template createIndexQuery(table: string): SqlQueryStr = - "CREATE INDEX IF NOT EXISTS i_rt ON " & table & " (receiverTimestamp);" + "CREATE INDEX IF NOT EXISTS i_msg ON " & table & " (contentTopic, pubsubTopic, senderTimestamp, id);" proc createIndex*(db: SqliteDatabase): DatabaseResult[void] {.inline.} = let query = createIndexQuery(DbTable) diff --git a/waku/v2/node/storage/migration/migration_types.nim b/waku/v2/node/storage/migration/migration_types.nim index 12b958c38..c2dd304c6 100644 --- a/waku/v2/node/storage/migration/migration_types.nim +++ b/waku/v2/node/storage/migration/migration_types.nim @@ -7,7 +7,7 @@ const MESSAGE_STORE_MIGRATION_PATH* = sourceDir / "migrations_scripts/message" const PEER_STORE_MIGRATION_PATH* = sourceDir / "migrations_scripts/peer" const ALL_STORE_MIGRATION_PATH* = sourceDir / "migrations_scripts" -const USER_VERSION* = 4 # increase this when there is an update in the database schema +const USER_VERSION* = 5 # increase this when there is an update in the database schema type MigrationScriptsResult*[T] = Result[T, string] type diff --git a/waku/v2/node/storage/migration/migrations_scripts/message/00005_updateIndex.up.sql b/waku/v2/node/storage/migration/migrations_scripts/message/00005_updateIndex.up.sql new file mode 100644 index 000000000..19cc8f81d --- /dev/null +++ b/waku/v2/node/storage/migration/migrations_scripts/message/00005_updateIndex.up.sql @@ -0,0 +1,3 @@ +DROP INDEX IF EXISTS i_rt; + +CREATE INDEX IF NOT EXISTS i_msg ON Message (contentTopic, pubsubTopic, senderTimestamp, id);