From b46df9fb40d3b93ad60030023d60d6d278c2adc0 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Tue, 2 May 2023 15:52:30 +0100 Subject: [PATCH 1/2] Ensure we always use index --- synapse/storage/databases/main/event_push_actions.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/synapse/storage/databases/main/event_push_actions.py b/synapse/storage/databases/main/event_push_actions.py index eeccf5db2433..6fdb1e292e6b 100644 --- a/synapse/storage/databases/main/event_push_actions.py +++ b/synapse/storage/databases/main/event_push_actions.py @@ -1836,6 +1836,15 @@ def remove_old_push_actions_that_have_rotated_txn( # deletes. batch_size = self._rotate_count + if isinstance(self.database_engine, PostgresEngine): + # Temporarily disable sequential scans in this transaction. We + # need to do this as the postgres statistics don't take into + # account the `highlight = 0` part when estimating the + # distribution of `stream_ordering`. I.e. since we keep old + # highlight rows the query planner thinks there are way more old + # rows to delete than there actually are. + txn.execute("SET LOCAL enable_seqscan=off") + txn.execute( """ SELECT stream_ordering FROM event_push_actions From 0049ad08a634afb9a5cd60a5885bcd308b8071ae Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Wed, 3 May 2023 14:00:49 +0100 Subject: [PATCH 2/2] Newsfile --- changelog.d/15531.misc | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/15531.misc diff --git a/changelog.d/15531.misc b/changelog.d/15531.misc new file mode 100644 index 000000000000..6d4da961b520 --- /dev/null +++ b/changelog.d/15531.misc @@ -0,0 +1 @@ +Speed up deleting of old rows in `event_push_actions`.