From b97b3755dc4cc02adcf12f61db8cca0783a7e17f Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Fri, 16 Jun 2023 12:58:57 +0300 Subject: [PATCH] Add index on message timestamps --- database/upgrades/00-latest-revision.sql | 4 +++- database/upgrades/57-message-timestamp-index.sql | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 database/upgrades/57-message-timestamp-index.sql diff --git a/database/upgrades/00-latest-revision.sql b/database/upgrades/00-latest-revision.sql index 4e1b5ea..dd799f1 100644 --- a/database/upgrades/00-latest-revision.sql +++ b/database/upgrades/00-latest-revision.sql @@ -1,4 +1,4 @@ --- v0 -> v56 (compatible with v45+): Latest revision +-- v0 -> v57 (compatible with v45+): Latest revision CREATE TABLE "user" ( mxid TEXT PRIMARY KEY, @@ -82,6 +82,8 @@ CREATE TABLE message ( FOREIGN KEY (chat_jid, chat_receiver) REFERENCES portal(jid, receiver) ON DELETE CASCADE ); +CREATE INDEX message_timestamp_idx ON message (chat_jid, chat_receiver, timestamp); + CREATE TABLE poll_option_id ( msg_mxid TEXT, opt_id TEXT, diff --git a/database/upgrades/57-message-timestamp-index.sql b/database/upgrades/57-message-timestamp-index.sql new file mode 100644 index 0000000..c6ebe13 --- /dev/null +++ b/database/upgrades/57-message-timestamp-index.sql @@ -0,0 +1,2 @@ +-- v57 (compatible with v45+): Add index for message timestamp to make read receipt handling faster +CREATE INDEX message_timestamp_idx ON message (chat_jid, chat_receiver, timestamp);