v2-0001-Add-RetrieveInstrumentationCustomScan-hook-for-Cu.patch

application/x-patch

Filename: v2-0001-Add-RetrieveInstrumentationCustomScan-hook-for-Cu.patch
Type: application/x-patch
Part: 0
Message: Re: [PATCH] Add RetrieveInstrumentation hook for CustomScan providers

Patch

Same data as JSON: GET /api/v1/attachments/:id/patch the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes. API reference →
Format: format-patch
Series: patch v2-0001
Subject: Add RetrieveInstrumentationCustomScan hook for CustomScan providers
File+
src/backend/executor/execParallel.c 3 0
src/backend/executor/nodeCustom.c 9 0
src/include/executor/nodeCustom.h 1 0
src/include/nodes/extensible.h 3 0
From 297ea1876dd6aa77ac59f1c9dbf5bd84eb726fb5 Mon Sep 17 00:00:00 2001
From: Siddharth Kothari <sidkot@google.com>
Date: Tue, 17 Feb 2026 12:23:56 +0000
Subject: [PATCH v2] 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 81b87d82fab..f9fe5347761 100644
--- a/src/backend/executor/execParallel.c
+++ b/src/backend/executor/execParallel.c
@@ -1166,6 +1166,9 @@ ExecParallelRetrieveInstrumentation(PlanState *planstate,
 		case T_TidRangeScanState:
 			ExecTidRangeScanRetrieveInstrumentation((TidRangeScanState *) 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 b7cc890cd20..bdb25d334a1 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,
-- 
2.55.0.795.g602f6c329a-goog