Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Speed up deleting of old rows in event_push_actions #15531

Merged
merged 2 commits into from
May 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/15531.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Speed up deleting of old rows in `event_push_actions`.
9 changes: 9 additions & 0 deletions synapse/storage/databases/main/event_push_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down