summary refs log tree commit diff
path: root/synapse/storage/search.py
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2016-04-21 17:16:11 +0100
committerErik Johnston <erik@matrix.org>2016-04-21 17:16:11 +0100
commit51bb339ab2130ab29ee9fcfec48d8e62f46c75f6 (patch)
treeb2aa9fdbb39ea611fb79038a69b0274fe3f305ae /synapse/storage/search.py
parentAdd missing run_upgrade (diff)
downloadsynapse-51bb339ab2130ab29ee9fcfec48d8e62f46c75f6.tar.xz
Create index concurrently
Diffstat (limited to 'synapse/storage/search.py')
-rw-r--r--synapse/storage/search.py14
1 files changed, 13 insertions, 1 deletions
diff --git a/synapse/storage/search.py b/synapse/storage/search.py
index 375057fa3e..548e9eeaef 100644
--- a/synapse/storage/search.py
+++ b/synapse/storage/search.py
@@ -141,10 +141,21 @@ class SearchStore(BackgroundUpdateStore):
         target_min_stream_id = progress["target_min_stream_id_inclusive"]
         max_stream_id = progress["max_stream_id_exclusive"]
         rows_inserted = progress.get("rows_inserted", 0)
+        have_added_index = progress['have_added_indexes']
 
         INSERT_CLUMP_SIZE = 1000
 
         def reindex_search_txn(txn):
+            if not have_added_index:
+                txn.execute(
+                    "CREATE INDEX CONCURRENTLY event_search_room_order ON event_search("
+                    "room_id, origin_server_ts, stream_ordering)"
+                )
+                txn.execute(
+                    "CREATE INDEX CONCURRENTLY event_search_order ON event_search("
+                    "origin_server_ts, stream_ordering)"
+                )
+
             sql = (
                 "SELECT stream_ordering, origin_server_ts, event_id FROM events"
                 " INNER JOIN event_search USING (room_id, event_id)"
@@ -173,7 +184,8 @@ class SearchStore(BackgroundUpdateStore):
             progress = {
                 "target_min_stream_id_inclusive": target_min_stream_id,
                 "max_stream_id_exclusive": min_stream_id,
-                "rows_inserted": rows_inserted + len(rows)
+                "rows_inserted": rows_inserted + len(rows),
+                "have_added_index": True,
             }
 
             self._background_update_progress_txn(