Use pg_class estimation for outgoing and dead letter table counts#2392
Merged
jeremydmiller merged 1 commit intomainfrom Mar 31, 2026
Merged
Use pg_class estimation for outgoing and dead letter table counts#2392jeremydmiller merged 1 commit intomainfrom
jeremydmiller merged 1 commit intomainfrom
Conversation
Replaces expensive select count(*) queries on the outgoing and dead_letter tables with pg_class reltuples-based estimation, matching the approach already used for partitioned incoming tables. Falls back to exact count only when the table has data but reltuples hasn't been updated by VACUUM/ANALYZE. Fixes #2377 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This was referenced Apr 1, 2026
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
Fixes #2377
Replaces expensive
select count(*)queries on thewolverine_outgoing_envelopesandwolverine_dead_letterstables withpg_class reltuples-based estimation inPostgresqlMessageStore.FetchCountsAsync().This matches the approach already used for the partitioned incoming table. The estimation uses PostgreSQL catalog statistics (
pg_class.reltuplesandpg_relation_size) which are virtually free compared to sequential scans. Falls back to exactcount(*)only when the table has physical data butreltupleshasn't been updated byVACUUM/ANALYZE.Before
After
Test plan
🤖 Generated with Claude Code