perf(mailqueue): cover amq_latest_send in the affecteduser index#2635
Merged
Conversation
fc9bf24 to
1079566
Compare
miaulalala
approved these changes
Jun 4, 2026
Signed-off-by: Git'Fellow <12234510+solracsf@users.noreply.github.com>
1079566 to
0ba0568
Compare
Collaborator
|
/backport to stable34 |
Collaborator
|
/backport to stable33 |
Collaborator
|
backport to stable32 |
Collaborator
|
/backport to stable32 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The email digest cron (
BackgroundJob\EmailNotification, which runs on every cron tick) callsMailQueueHandler::getAffectedUsers():The amp_user index only contained
amq_affecteduser, soMIN(amq_latest_send)could not be served from the index. MariaDB/MySQL therefore scanned the entire queue and built a temporary table to resolve theGROUP BYon every run..This PR widens that index to (
amq_affecteduser,amq_latest_send), which lets the engine resolve the aggregate with a loose index scan (Using index for group-by), reading one entry per user instead of the whole queue. amp_user is a strict prefix of the new index and becomes redundant, so it is dropped (no net change in index count).MariaDB 10.11,
activity_mqseeded with a ~60k-row backlog across 9 users:Handler_read_next(index rows walked)amp_userUsing temporary; Using filesortamp_user_sendUsing index for group-byThe result set is identical before and after (verified with
FORCE INDEXvsIGNORE INDEX).