Tighten asserts on ParallelWorkerNumber a little bit

Tomas Vondra <tomas@vondra.me>

From: Tomas Vondra <tomas@vondra.me>
To: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Date: 2026-03-12T18:59:43Z
Lists: pgsql-hackers

Attachments

Hi,

While hacking on something I happened to notice a couple asserts on
ParallelWorkerNumber when collecting shared instrumentation:

  Assert(ParallelWorkerNumber <= node->shared_info->num_workers);

This is not quire right, because num_workers is used to size arrays
indexed by ParallelWorkerNumber. And the comment in parallel.c also
claims (ParallelWorkerNumber < num_workers).

So AFAICS the assert(s) should be

  Assert(ParallelWorkerNumber < node->shared_info->num_workers);

I don't think we had issues with this not catching a bug. But it may be
a bit misleading, so worth fixing and (probably) backpatching.


regards

-- 
Tomas Vondra

Commits

  1. Tighten asserts on ParallelWorkerNumber