From e92ca3e4726e764cffba8f35f75665883ac15595 Mon Sep 17 00:00:00 2001 From: Olivier 'reivilibre Date: Fri, 10 Jan 2025 17:31:31 +0000 Subject: [PATCH] Add index to sliding_sync_membership_snapshots(membership_event_id) To address a performance problem due to the foreign key on the same column. --- synapse/storage/databases/main/sliding_sync.py | 9 ++++++++- .../07_sliding_sync_membership_snapshot_index.sql | 15 +++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 synapse/storage/schema/main/delta/88/07_sliding_sync_membership_snapshot_index.sql diff --git a/synapse/storage/databases/main/sliding_sync.py b/synapse/storage/databases/main/sliding_sync.py index 874dfdcb77a..a287fd2a3fd 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 @@ def __init__( 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/88/07_sliding_sync_membership_snapshot_index.sql b/synapse/storage/schema/main/delta/88/07_sliding_sync_membership_snapshot_index.sql new file mode 100644 index 00000000000..1be484ea191 --- /dev/null +++ b/synapse/storage/schema/main/delta/88/07_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: +-- . + +INSERT INTO background_updates (ordering, update_name, progress_json) VALUES + (8807, 'sliding_sync_membership_snapshots_membership_event_id_idx', '{}');