summary refs log tree commit diff
diff options
context:
space:
mode:
authorErik Johnston <erikj@element.io>2024-04-04 11:05:40 +0100
committerGitHub <noreply@github.com>2024-04-04 11:05:40 +0100
commit31122b71bcf29b4a034be4fc14770f4b8a45b2c5 (patch)
treeda60a43fc6057827f6b8fff71eaa69622f4fb108
parentMerge branch 'master' into develop (diff)
downloadsynapse-31122b71bcf29b4a034be4fc14770f4b8a45b2c5.tar.xz
Add missing index to `access_tokens` table (#17045)
This was causing sequential scans when using refresh tokens.
-rw-r--r--changelog.d/17045.misc1
-rw-r--r--synapse/storage/databases/main/registration.py7
2 files changed, 8 insertions, 0 deletions
diff --git a/changelog.d/17045.misc b/changelog.d/17045.misc
new file mode 100644
index 0000000000..0d042a43ff
--- /dev/null
+++ b/changelog.d/17045.misc
@@ -0,0 +1 @@
+Improve database performance by adding a missing index to `access_tokens.refresh_token_id`.
diff --git a/synapse/storage/databases/main/registration.py b/synapse/storage/databases/main/registration.py
index d939ade427..30a3ae3055 100644
--- a/synapse/storage/databases/main/registration.py
+++ b/synapse/storage/databases/main/registration.py
@@ -2266,6 +2266,13 @@ class RegistrationStore(StatsStore, RegistrationBackgroundUpdateStore):
     ):
         super().__init__(database, db_conn, hs)
 
+        self.db_pool.updates.register_background_index_update(
+            update_name="access_tokens_refresh_token_id_idx",
+            index_name="access_tokens_refresh_token_id_idx",
+            table="access_tokens",
+            columns=("refresh_token_id",),
+        )
+
         self._ignore_unknown_session_error = (
             hs.config.server.request_token_inhibit_3pid_errors
         )