← ClaudeAtlas

parallel-querylisted

Add parallel-aware C code in a PostgreSQL backend patch or extension — covers ParallelContext lifecycle (EnterParallelMode / CreateParallelContext / InitializeParallelDSM / LaunchParallelWorkers / WaitForParallelWorkersToFinish / DestroyParallelContext / ExitParallelMode), shm_toc DSM allocation + key lookup, ExecXXXInitializeDSM / ExecXXXInitializeWorker / ExecXXXReInitializeDSM hooks on plan nodes, and parallel-safety markings (pg_proc.proparallel s/r/u; PARALLEL SAFE / RESTRICTED / UNSAFE). Use whenever a PG patch or extension adds parallel-aware code, picks PARALLEL SAFE/RESTRICTED/UNSAFE for a SQL-callable function, extends execParallel.c, plumbs a worker shmem state via shm_toc, or debugs a parallel worker DSM/TOC issue. Skip for DBA tuning of max_parallel_workers GUC, OpenMP / CUDA / pthread / Tokio / Go-goroutine parallelism, JavaScript Promise.all and async-iter parallel fetches, generic worker-pool questions, and ML data-parallel training.
matejformanek/postgres-claude · ★ 0 · AI & Automation · score 70
Install: claude install-skill matejformanek/postgres-claude
# parallel-query — parallel-query infrastructure This is the procedural cookbook for parallel-query infrastructure in the backend and in extensions. For the conceptual model see `knowledge/idioms/bgworker-and-parallel.md` and `knowledge/docs-distilled/parallel-query.md`. This skill is one of three siblings that share the `_PG_init` / postmaster-lifecycle boundary: - `gucs-config` — custom GUC variables. - `bgworker-and-extensions` — RegisterBackgroundWorker, shared-library hooks. - **parallel-query** (this skill) — ParallelContext + parallel-safe markings. ## 1. Two layers — pick the right one | Goal | Use | |---|---| | Build a parallel-aware **executor node** | Plumb into `execParallel.c` (override `ExecXXXInitializeDSM` / `ExecXXXInitializeWorker`). See `executor-and-planner`. | | Run arbitrary parallel C code from an extension | Use the `ParallelContext` API directly (`access/parallel.h`) — §3 below. | | Just expose a function to a query that may run in parallel | Mark it `PARALLEL SAFE` in `pg_proc.dat` and that's it. §2 below. | ## 2. Function parallel-safety markings Catalog column `pg_proc.proparallel`. [verified-by-code `source/src/include/catalog/pg_proc.h:79`] | Value | SQL keyword | Meaning | |---|---|---| | `s` (default) | `PARALLEL SAFE` | Function may run in a worker. | | `r` | `PARALLEL RESTRICTED` | Function may run in the leader only when plan is parallel. | | `u` | `PARALLEL UNSAFE` | Plan must not be parallelised at all. | Use **UNSAFE** if the func