Dear PostgreSQL Hackers, This email proposes a patch to enhance the CustomScan provider interface. The patch file, 0001-Add-RetrieveInstrumentationCustomScan-hook-for-Custo.patch, is attached.
*Problem:* CustomScan providers currently lack a standard method to aggregate instrumentation data from parallel workers back to the leader process before the Dynamic Shared Memory (DSM) segment is unlinked. This makes it difficult to gather comprehensive performance metrics from parallelized custom scans. *Solution:* This patch introduces a new optional hook, RetrieveInstrumentationCustomScan, to the CustomExecMethods struct. This hook allows custom scan providers to implement logic to collect and consolidate instrumentation from shared memory or worker states during the parallel query cleanup phase. This hook is invoked via the new ExecCustomScanRetrieveInstrumentation function, called from ExecParallelRetrieveInstrumentation for T_CustomScanState nodes. Since the hook is optional (checked for NULL before calling), it maintains full backward compatibility. *Testing & Compatibility:* - The patch compiles and passes all core regression tests (make check-world) on my x86_64 instance. - The changes are not platform-specific. - Regression Tests: This patch provides a new *capability* for custom scan providers. Since the hook's functionality is only realized when implemented by an extension, specific tests would naturally reside within that extension rather than in the core regression suite. This patch does not directly address a specific item on the official TODO list but enhances the extensibility framework. I believe this patch is complete and ready for review. I look forward to any feedback and am happy to make revisions. I will also add this patch to the next CommitFest. Thank you, Siddharth Kothari
From ac6049e8b0af21666314edb73018fd99940d0731 Mon Sep 17 00:00:00 2001 From: Siddharth Kothari <[email protected]> Date: Tue, 17 Feb 2026 12:23:56 +0000 Subject: [PATCH] Add RetrieveInstrumentationCustomScan hook for CustomScan providers CustomScan providers currently lack a standard method to aggregate instrumentation data from parallel workers back to the leader process before the Dynamic Shared Memory segment is destroyed. This patch introduces an optional RetrieveInstrumentationCustomScan callback to the CustomExecMethods struct. This allows custom scan providers to implement logic to collect and consolidate instrumentation from shared memory. The new hook is called in ExecRetrieveInstrumentation for CustomScanState nodes during the parallel query cleanup phase. --- src/backend/executor/execParallel.c | 3 +++ src/backend/executor/nodeCustom.c | 9 +++++++++ src/include/executor/nodeCustom.h | 1 + src/include/nodes/extensible.h | 3 +++ 4 files changed, 16 insertions(+) diff --git a/src/backend/executor/execParallel.c b/src/backend/executor/execParallel.c index f87978c137e..c2416a98170 100644 --- a/src/backend/executor/execParallel.c +++ b/src/backend/executor/execParallel.c @@ -1118,6 +1118,9 @@ ExecParallelRetrieveInstrumentation(PlanState *planstate, case T_BitmapHeapScanState: ExecBitmapHeapRetrieveInstrumentation((BitmapHeapScanState *) planstate); break; + case T_CustomScanState: + ExecCustomScanRetrieveInstrumentation((CustomScanState *) planstate); + break; default: break; } diff --git a/src/backend/executor/nodeCustom.c b/src/backend/executor/nodeCustom.c index a9ad5af6a98..f027d24993f 100644 --- a/src/backend/executor/nodeCustom.c +++ b/src/backend/executor/nodeCustom.c @@ -217,6 +217,15 @@ ExecCustomScanInitializeWorker(CustomScanState *node, } } +void +ExecCustomScanRetrieveInstrumentation(CustomScanState *node) +{ + const CustomExecMethods *methods = node->methods; + + if (methods->RetrieveInstrumentationCustomScan) + methods->RetrieveInstrumentationCustomScan(node); +} + void ExecShutdownCustomScan(CustomScanState *node) { diff --git a/src/include/executor/nodeCustom.h b/src/include/executor/nodeCustom.h index fb0acc6e414..0a9cfb40381 100644 --- a/src/include/executor/nodeCustom.h +++ b/src/include/executor/nodeCustom.h @@ -37,6 +37,7 @@ extern void ExecCustomScanReInitializeDSM(CustomScanState *node, ParallelContext *pcxt); extern void ExecCustomScanInitializeWorker(CustomScanState *node, ParallelWorkerContext *pwcxt); +extern void ExecCustomScanRetrieveInstrumentation(CustomScanState *node); extern void ExecShutdownCustomScan(CustomScanState *node); #endif /* NODECUSTOM_H */ diff --git a/src/include/nodes/extensible.h b/src/include/nodes/extensible.h index 517db95c4a3..cda478b538f 100644 --- a/src/include/nodes/extensible.h +++ b/src/include/nodes/extensible.h @@ -151,6 +151,9 @@ typedef struct CustomExecMethods void *coordinate); void (*ShutdownCustomScan) (CustomScanState *node); + /* Optional: retrieve parallel instrumentation */ + void (*RetrieveInstrumentationCustomScan) (CustomScanState *node); + /* Optional: print additional information in EXPLAIN */ void (*ExplainCustomScan) (CustomScanState *node, List *ancestors, --
