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

Commit

Permalink
ANALYZE new stream ordering column (#10326)
Browse files Browse the repository at this point in the history
Fixes #10325
  • Loading branch information
babolivier committed Jul 7, 2021
1 parent 9947224 commit 9ad8455
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions changelog.d/10326.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix a long-standing bug where Synapse would return errors after 2<sup>31</sup> events were handled by the server.
10 changes: 10 additions & 0 deletions synapse/storage/databases/main/events_bg_updates.py
Original file line number Diff line number Diff line change
Expand Up @@ -1146,6 +1146,16 @@ def process(txn: Cursor) -> None:
logger.info("completing stream_ordering migration: %s", sql)
txn.execute(sql)

# ANALYZE the new column to build stats on it, to encourage PostgreSQL to use the
# indexes on it.
# We need to pass execute a dummy function to handle the txn's result otherwise
# it tries to call fetchall() on it and fails because there's no result to fetch.
await self.db_pool.execute(
"background_analyze_new_stream_ordering_column",
lambda txn: None,
"ANALYZE events(stream_ordering2)",
)

await self.db_pool.runInteraction(
"_background_replace_stream_ordering_column", process
)
Expand Down

0 comments on commit 9ad8455

Please sign in to comment.