Skip to content

Use pg_class estimation for outgoing and dead letter table counts#2392

Merged
jeremydmiller merged 1 commit intomainfrom
pg-dlq-metrics-estimation
Mar 31, 2026
Merged

Use pg_class estimation for outgoing and dead letter table counts#2392
jeremydmiller merged 1 commit intomainfrom
pg-dlq-metrics-estimation

Conversation

@jeremydmiller
Copy link
Copy Markdown
Member

Summary

Fixes #2377

Replaces expensive select count(*) queries on the wolverine_outgoing_envelopes and wolverine_dead_letters tables with pg_class reltuples-based estimation in PostgresqlMessageStore.FetchCountsAsync().

This matches the approach already used for the partitioned incoming table. The estimation uses PostgreSQL catalog statistics (pg_class.reltuples and pg_relation_size) which are virtually free compared to sequential scans. Falls back to exact count(*) only when the table has physical data but reltuples hasn't been updated by VACUUM/ANALYZE.

Before

select count(*) from schema.wolverine_outgoing_envelopes   -- full sequential scan
select count(*) from schema.wolverine_dead_letters          -- full sequential scan

After

-- Fast catalog lookup, no table scan
select (case when c.reltuples < 0 then 0 ... end)::bigint as estimated_count, ...
from pg_catalog.pg_class c ...
where c.relname = 'wolverine_outgoing_envelopes';

Test plan

  • Build succeeds
  • 15 durability tests pass
  • 3 PostgreSQL-specific tests pass (10 failures are pre-existing SQL Server connection issues)

🤖 Generated with Claude Code

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PostgresqlMessageStore DLQ metrics need to use the table size estimation

1 participant