summary refs log tree commit diff
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2018-09-13 15:05:52 +0100
committerErik Johnston <erik@matrix.org>2018-09-13 15:05:52 +0100
commit9dbe38ea7de66f6e5dfab1570dd3a5217a4883eb (patch)
treee7ee716526bfd20404ee002ea5003db7ec3259d6
parentMerge branch 'develop' of github.com:matrix-org/synapse into erikj/speed_up_p... (diff)
downloadsynapse-9dbe38ea7de66f6e5dfab1570dd3a5217a4883eb.tar.xz
Create indices after insertion
-rw-r--r--synapse/storage/events.py32
1 files changed, 18 insertions, 14 deletions
diff --git a/synapse/storage/events.py b/synapse/storage/events.py
index 1c8e01a47e..622f2ababf 100644
--- a/synapse/storage/events.py
+++ b/synapse/storage/events.py
@@ -1890,20 +1890,6 @@ class EventsStore(EventFederationStore, EventsWorkerStore, BackgroundUpdateStore
             ")"
         )
 
-        # create an index on should_delete because later we'll be looking for
-        # the should_delete / shouldn't_delete subsets
-        txn.execute(
-            "CREATE INDEX events_to_purge_should_delete"
-            " ON events_to_purge(should_delete)",
-        )
-
-        # We do joins against events_to_purge for e.g. calculating state
-        # groups to purge, etc., so lets make an index.
-        txn.execute(
-            "CREATE INDEX events_to_purge_id"
-            " ON events_to_purge(event_id)",
-        )
-
         # First ensure that we're not about to delete all the forward extremeties
         txn.execute(
             "SELECT e.event_id, e.depth FROM events as e "
@@ -1950,6 +1936,24 @@ class EventsStore(EventFederationStore, EventsWorkerStore, BackgroundUpdateStore
             ),
             should_delete_params,
         )
+
+        # We create the indices *after* insertion as that's a lot faster.
+
+        # create an index on should_delete because later we'll be looking for
+        # the should_delete / shouldn't_delete subsets
+        txn.execute(
+            "CREATE INDEX events_to_purge_should_delete"
+            " ON events_to_purge(should_delete)",
+        )
+
+        # We do joins against events_to_purge for e.g. calculating state
+        # groups to purge, etc., so lets make an index.
+        txn.execute(
+            "CREATE INDEX events_to_purge_id"
+            " ON events_to_purge(event_id)",
+        )
+
+
         txn.execute(
             "SELECT event_id, should_delete FROM events_to_purge"
         )