Skip to content

Fix resqueue#1608

Draft
lss602726449 wants to merge 2 commits intoapache:cbdb-postgres-mergefrom
lss602726449:fix_contrb1
Draft

Fix resqueue#1608
lss602726449 wants to merge 2 commits intoapache:cbdb-postgres-mergefrom
lss602726449:fix_contrb1

Conversation

@lss602726449
Copy link
Contributor

Fixes #ISSUE_Number

What does this PR do?

Type of Change

  • Bug fix (non-breaking change)
  • New feature (non-breaking change)
  • Breaking change (fix or feature with breaking changes)
  • Documentation update

Breaking Changes

Test Plan

  • Unit tests added/updated
  • Integration tests added/updated
  • Passed make installcheck
  • Passed make -C src/test installcheck-cbdb-parallel

Impact

Performance:

User-facing changes:

Dependencies:

Checklist

Additional Context

CI Skip Instructions


liushengsong and others added 2 commits March 10, 2026 21:08
Adds a new PGSTAT_KIND_RESQUEUE statistics kind that tracks per-queue
throughput and latency counters, exposed through the pg_stat_resqueues
view and pg_stat_get_resqueue_stats() SQL function.

New statistics tracked per resource queue:
- queries_submitted / admitted / rejected / completed
- elapsed_wait_secs / max_wait_secs
- elapsed_exec_secs / max_exec_secs
- total_cost / total_memory_kb
- stat_reset_timestamp

Implementation notes:
- All stat updates use pgstat_get_entry_ref_locked() to write directly
  to shared memory, bypassing the pending/flush mechanism.  This makes
  stats immediately visible without explicit flushes, and is safe when
  called from PG_CATCH blocks (pgstat_resqueue_rejected is invoked
  inside PG_CATCH in ResLockPortal/ResLockUtilityPortal).
- Per-portal timing is tracked in a backend-local hash table keyed by
  portalid; entries are removed when the portal is admitted, rejected,
  or completed.

Also fixes a pre-existing bug in resqueue.c: dclist_delete_from()
already decrements waitProcs.count internally, but three call sites
additionally did a manual count-- causing count to underflow to
UINT32_MAX.  The next dclist_push_tail() would then overflow count
back to 0 and trip the overflow assertion in ResProcSleep, crashing
the backend.

New files:
- src/backend/utils/activity/pgstat_resqueue.c
- src/test/isolation2/sql/resqueue_stats.sql
- src/test/isolation2/expected/resqueue_stats.out

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ributed tables

In GPDB, DML (INSERT/UPDATE/DELETE) executes on QE segments, but
autovacuum lives on the QD coordinator.  Before this change the QD
never received modification counts from QEs, so n_mod_since_analyze
remained 0 and auto-ANALYZE never triggered for distributed tables.

Add two functions:
- pgstat_send_qd_tabstats() (QE side, pgstat.c): reads per-table
  counts from pgStatXactStack before finish_xact_command() NULLs it,
  serialises them as PgStatTabRecordFromQE[] and attaches the array to
  the libpq PGresult via extras/PGExtraTypeTableStats.
- pgstat_combine_from_qe() (QD side, pgstat_relation.c): called from
  mppExecutorFinishup/mppExecutorWait after dispatch; iterates QE
  results, deserialises PgStatTabRecordFromQE arrays and merges each
  record into the QD's pending stats via pgstat_prep_relation_pending(),
  then calls pgstat_force_next_flush() to bypass rate-limiting.

Using the pending path (rather than writing directly to shared memory)
is critical when auto_stats triggers ANALYZE in the same command:
pgstat_report_analyze() resets mod_since_analyze to 0, but pending
counts are added back when pgstat_report_stat() flushes after ANALYZE.

Also add pgstat_get_current_xact_stack() to read pgStatXactStack
without side effects, and update the Makefile to include libpq_srcdir
for libpq-int.h (PGExtraType, pg_result internals).

The autovacuum-analyze isolation2 test verifies all four auto-ANALYZE
scenarios: plain heap table, partition leaf tables, lock-conflict abort,
and coexistence with auto_stats (on_no_stats / on_change / below
threshold).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@lss602726449 lss602726449 changed the title Fix contrb1 Fix resqueue Mar 10, 2026
@lss602726449 lss602726449 marked this pull request as draft March 10, 2026 13:10
@lss602726449 lss602726449 marked this pull request as ready for review March 10, 2026 13:11
@lss602726449 lss602726449 marked this pull request as draft March 10, 2026 13:12
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.

1 participant