Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add index to speed up Message.find_recent query #862

Merged
merged 3 commits into from
Nov 1, 2022

Conversation

AndrewFerr
Copy link
Contributor

This optimizes the heavy query made by Message.find_recent added by 026c39a in v0.12.1:

SELECT mxid, mx_room, tgid, tg_space, edit_index, redacted, content_hash, sender_mxid, sender FROM message
WHERE mx_room=$1 AND sender<>$2
ORDER BY tgid DESC LIMIT $3

Similar to #845, this was needed to unblock overloading our RDS on long queries. Here's a chart of the DB load 1) before upgrading to v0.12.1, 2) after upgrading, and 3) after adding the index (and killing hung leftover queries).
image

Prevent some new DB upgrades from failing if an index they try to create
already exists. This allows for manually adding an index to a live DB
before its schema is "officially" upgraded.
@tulir tulir merged commit d798708 into mautrix:master Nov 1, 2022
@AndrewFerr AndrewFerr deleted the index-for-message-find-recent branch January 31, 2024 13:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants