Tighten asserts on ParallelWorkerNumber

Tomas Vondra <tomas.vondra@postgresql.org>

Commit: 0e5ff9b9b45a657aea12440478dc002e9b01f138
Author: Tomas Vondra <tomas.vondra@postgresql.org>
Date: 2026-03-14T14:27:56Z
Releases: 18.4
Tighten asserts on ParallelWorkerNumber

The comment about ParallelWorkerNumbr in parallel.c says:

  In parallel workers, it will be set to a value >= 0 and < the number
  of workers before any user code is invoked; each parallel worker will
  get a different parallel worker number.

However asserts in various places collecting instrumentation allowed
(ParallelWorkerNumber == num_workers). That would be a bug, as the value
is used as index into an array with num_workers entries.

Fixed by adjusting the asserts accordingly. Backpatch to all supported
versions.

Discussion: https://postgr.es/m/5db067a1-2cdf-4afb-a577-a04f30b69167@vondra.me
Reviewed-by: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
Backpatch-through: 14

Files

Discussion