Skip to content

perf(mailqueue): cover amq_latest_send in the affecteduser index#2635

Merged
miaulalala merged 1 commit into
masterfrom
perf/mail-queue-affecteduser-index
Jun 4, 2026
Merged

perf(mailqueue): cover amq_latest_send in the affecteduser index#2635
miaulalala merged 1 commit into
masterfrom
perf/mail-queue-affecteduser-index

Conversation

@solracsf

@solracsf solracsf commented Jun 3, 2026

Copy link
Copy Markdown
Member

Summary

The email digest cron (BackgroundJob\EmailNotification, which runs on every cron tick) calls
MailQueueHandler::getAffectedUsers():

SELECT amq_affecteduser, MIN(amq_latest_send)
  FROM activity_mq
  WHERE amq_latest_send < ?
  GROUP BY amq_affecteduser
  ORDER BY MIN(amq_latest_send) ASC

The amp_user index only contained amq_affecteduser, so MIN(amq_latest_send) could not be served from the index. MariaDB/MySQL therefore scanned the entire queue and built a temporary table to resolve the GROUP BY on 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_mq seeded with a ~60k-row backlog across 9 users:

index Handler_read_next (index rows walked) plan
before amp_user 60,108 full index scan + Using temporary; Using filesort
after amp_user_send 0 (18 seeks) Using index for group-by

The result set is identical before and after (verified with FORCE INDEX vs IGNORE INDEX).

@solracsf solracsf force-pushed the perf/mail-queue-affecteduser-index branch from fc9bf24 to 1079566 Compare June 3, 2026 08:19
@solracsf solracsf self-assigned this Jun 3, 2026
@solracsf solracsf requested a review from miaulalala June 4, 2026 07:29
Comment thread lib/Migration/Version8000Date20260603120000.php Outdated
Signed-off-by: Git'Fellow <12234510+solracsf@users.noreply.github.com>
@solracsf solracsf force-pushed the perf/mail-queue-affecteduser-index branch from 1079566 to 0ba0568 Compare June 4, 2026 08:48
@miaulalala miaulalala merged commit 139bd9a into master Jun 4, 2026
53 checks passed
@miaulalala miaulalala deleted the perf/mail-queue-affecteduser-index branch June 4, 2026 08:59
@miaulalala

Copy link
Copy Markdown
Collaborator

/backport to stable34

@miaulalala

Copy link
Copy Markdown
Collaborator

/backport to stable33

@miaulalala

Copy link
Copy Markdown
Collaborator

backport to stable32

@miaulalala

Copy link
Copy Markdown
Collaborator

/backport to stable32

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants