diff --git a/synapse/storage/databases/main/sliding_sync.py b/synapse/storage/databases/main/sliding_sync.py
index 874dfdcb77..a287fd2a3f 100644
--- a/synapse/storage/databases/main/sliding_sync.py
+++ b/synapse/storage/databases/main/sliding_sync.py
@@ -1,7 +1,7 @@
#
# This file is licensed under the Affero General Public License (AGPL) version 3.
#
-# Copyright (C) 2023 New Vector, Ltd
+# Copyright (C) 2023, 2025 New Vector, Ltd
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
@@ -61,6 +61,13 @@ class SlidingSyncStore(SQLBaseStore):
columns=("required_state_id",),
)
+ self.db_pool.updates.register_background_index_update(
+ update_name="sliding_sync_membership_snapshots_membership_event_id_idx",
+ index_name="sliding_sync_membership_snapshots_membership_event_id_idx",
+ table="sliding_sync_membership_snapshots",
+ columns=("membership_event_id",),
+ )
+
async def get_latest_bump_stamp_for_room(
self,
room_id: str,
diff --git a/synapse/storage/schema/main/delta/89/01_sliding_sync_membership_snapshot_index.sql b/synapse/storage/schema/main/delta/89/01_sliding_sync_membership_snapshot_index.sql
new file mode 100644
index 0000000000..7799cffdce
--- /dev/null
+++ b/synapse/storage/schema/main/delta/89/01_sliding_sync_membership_snapshot_index.sql
@@ -0,0 +1,15 @@
+--
+-- This file is licensed under the Affero General Public License (AGPL) version 3.
+--
+-- Copyright (C) 2025 New Vector, Ltd
+--
+-- This program is free software: you can redistribute it and/or modify
+-- it under the terms of the GNU Affero General Public License as
+-- published by the Free Software Foundation, either version 3 of the
+-- License, or (at your option) any later version.
+--
+-- See the GNU Affero General Public License for more details:
+-- <https://www.gnu.org/licenses/agpl-3.0.html>.
+
+INSERT INTO background_updates (ordering, update_name, progress_json) VALUES
+ (8901, 'sliding_sync_membership_snapshots_membership_event_id_idx', '{}');
|