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

Commit 28ac1a1

Browse files
authored
Speed up deleting of old rows in event_push_actions (#15531)
Enforce that we use index scans (rather than seq scans), which we also do for state queries. The reason to enforce this is that we can't correctly get PostgreSQL to understand the distribution of `stream_ordering` depends on `highlight`, and so it always defaults (on matrix.org) to sequential scans.
1 parent fc3a878 commit 28ac1a1

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

changelog.d/15531.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Speed up deleting of old rows in `event_push_actions`.

synapse/storage/databases/main/event_push_actions.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1612,6 +1612,15 @@ def remove_old_push_actions_that_have_rotated_txn(
16121612
# deletes.
16131613
batch_size = self._rotate_count
16141614

1615+
if isinstance(self.database_engine, PostgresEngine):
1616+
# Temporarily disable sequential scans in this transaction. We
1617+
# need to do this as the postgres statistics don't take into
1618+
# account the `highlight = 0` part when estimating the
1619+
# distribution of `stream_ordering`. I.e. since we keep old
1620+
# highlight rows the query planner thinks there are way more old
1621+
# rows to delete than there actually are.
1622+
txn.execute("SET LOCAL enable_seqscan=off")
1623+
16151624
txn.execute(
16161625
"""
16171626
SELECT stream_ordering FROM event_push_actions

0 commit comments

Comments
 (0)