smp-server: rework message expiration - #1873
Open
shumvgolove wants to merge 1 commit into
Open
shumvgolove wants to merge 1 commit into
shumvgolove wants to merge 1 commit into
Conversation
shumvgolove
requested review from
epoberezkin and
spaced4ndy
as code owners
September 19, 2026 10:22
This branch has not been deployed
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.
Problem: the expiration sweep iterated every non-empty queue, doing a per-queue probe and
COMMITto find that most had nothing to expire. Cost is proportional to the number of non-empty queues times the per-queue commit, while only a small fraction of queues hold expired messages.Change:
delete_expired_msgsruns only on those, committing in batches.idx_messages_expire (msg_ts, recipient_id) WHERE NOT msg_quota.msg_queue_expire(column andidx_msg_queues_expire): no query reads it for a decision after this change, and removing it also removes the flag update that defeated HOT updates.idx_messages_recipient_id_msg_ts(unused; covered byrecipient_id_message_id). Keepsrecipient_id_msg_quota(in use).Verification:
msg_queuescounters andmessagesare byte-identical.delete_expired_msgscalls drop from 20,000 to 1,000 for the identical result, with discovery via Index Only Scan.server_schema.sqlmatches pg_dump 15 output; the down migration restores the prior schema exceptmsg_queue_expirecolumn order (added to the schema-test down-skip list, as with20250320_short_links). Library and test suite compile.