mirror of
https://github.com/element-hq/synapse.git
synced 2025-03-28 10:28:32 +00:00
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.
This commit is contained in:
parent
fc3a878220
commit
28ac1a1a91
2 changed files with 10 additions and 0 deletions
1
changelog.d/15531.misc
Normal file
1
changelog.d/15531.misc
Normal file
|
@ -0,0 +1 @@
|
|||
Speed up deleting of old rows in `event_push_actions`.
|
|
@ -1612,6 +1612,15 @@ class EventPushActionsWorkerStore(ReceiptsWorkerStore, StreamWorkerStore, SQLBas
|
|||
# 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
|
||||
|
|
Loading…
Add table
Reference in a new issue