summary refs log tree commit diff
path: root/synapse/storage/databases
diff options
context:
space:
mode:
authorBrendan Abolivier <babolivier@matrix.org>2021-07-07 11:56:17 +0200
committerGitHub <noreply@github.com>2021-07-07 11:56:17 +0200
commit9ad84558951dd970dc2a362c923552141a42a5f3 (patch)
tree2e93726f9840fd77780e649e0e185eec1cb8e88c /synapse/storage/databases
parentSmall changelog tweaks (diff)
downloadsynapse-9ad84558951dd970dc2a362c923552141a42a5f3.tar.xz
ANALYZE new stream ordering column (#10326)
Fixes #10325
Diffstat (limited to 'synapse/storage/databases')
-rw-r--r--synapse/storage/databases/main/events_bg_updates.py10
1 files changed, 10 insertions, 0 deletions
diff --git a/synapse/storage/databases/main/events_bg_updates.py b/synapse/storage/databases/main/events_bg_updates.py
index 1c95c66648..29f33bac55 100644
--- a/synapse/storage/databases/main/events_bg_updates.py
+++ b/synapse/storage/databases/main/events_bg_updates.py
@@ -1146,6 +1146,16 @@ class EventsBackgroundUpdatesStore(SQLBaseStore):
                 logger.info("completing stream_ordering migration: %s", sql)
                 txn.execute(sql)
 
+        # ANALYZE the new column to build stats on it, to encourage PostgreSQL to use the
+        # indexes on it.
+        # We need to pass execute a dummy function to handle the txn's result otherwise
+        # it tries to call fetchall() on it and fails because there's no result to fetch.
+        await self.db_pool.execute(
+            "background_analyze_new_stream_ordering_column",
+            lambda txn: None,
+            "ANALYZE events(stream_ordering2)",
+        )
+
         await self.db_pool.runInteraction(
             "_background_replace_stream_ordering_column", process
         )