-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Optimize hash queries with lookup table (#2933)
* Upgrade Postgres schema to add messages_lookup table * Perform optimized query for messageHash-only queries
- Loading branch information
1 parent
8584b94
commit 6463885
Showing
8 changed files
with
298 additions
and
37 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
migrations/message_store_postgres/content_script_version_7.nim
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
const ContentScriptVersion_7* = | ||
""" | ||
-- Create lookup table | ||
CREATE TABLE IF NOT EXISTS messages_lookup ( | ||
timestamp BIGINT NOT NULL, | ||
messageHash VARCHAR NOT NULL | ||
); | ||
-- Put data into lookup table | ||
INSERT INTO messages_lookup (messageHash, timestamp) SELECT messageHash, timestamp from messages; | ||
ALTER TABLE messages_lookup ADD CONSTRAINT messageIndexLookupTable PRIMARY KEY (messageHash, timestamp); | ||
-- Create indexes | ||
CREATE INDEX IF NOT EXISTS idx_messages_messagehash ON messages (messagehash); | ||
CREATE INDEX IF NOT EXISTS idx_messages_timestamp ON messages (timestamp); | ||
CREATE INDEX IF NOT EXISTS idx_messages_lookup_messagehash ON messages_lookup (messagehash); | ||
CREATE INDEX IF NOT EXISTS idx_messages_lookup_timestamp ON messages_lookup (timestamp); | ||
DROP INDEX IF EXISTS i_query_storedat; | ||
DROP INDEX IF EXISTS i_query; | ||
CREATE INDEX IF NOT EXISTS idx_query_pubsubtopic ON messages (pubsubTopic); | ||
CREATE INDEX IF NOT EXISTS idx_query_contenttopic ON messages (contentTopic); | ||
-- Update to new version | ||
UPDATE version SET version = 7 WHERE version = 6; | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.