public inbox for [email protected]  
help / color / mirror / Atom feed
From: Siddharth Kothari <[email protected]>
To: [email protected]
Cc: Vaibhav Jain <[email protected]>
Cc: Madhukar <[email protected]>
Cc: [email protected]
Cc: [email protected]
Subject: Re: [PATCH] Add RetrieveInstrumentation hook for CustomScan providers
Date: Wed, 8 Jul 2026 22:22:51 +0530
Message-ID: <CAGCUe0JRZP-=rOefQz0AYLPpeg=EN=a=TcD9=ZSDup1Mn+Sanw@mail.gmail.com> (raw)
In-Reply-To: <CAGCUe0+DV0Tkd19rX7HrQikyuWTF0uQS-OeikeMOye+CzSvxgQ@mail.gmail.com>
References: <CAGCUe0Kp7kTUWFjHhiE-xjZ4=UDe2fUdDVajKcjV+BT+T5d21A@mail.gmail.com>
	<CAGCUe0LUtEDyy1U-KLzax3KGz6zA8T75d4VxN+3vu_9EmLMeLQ@mail.gmail.com>
	<CAGCUe0+DV0Tkd19rX7HrQikyuWTF0uQS-OeikeMOye+CzSvxgQ@mail.gmail.com>

Hi hackers,

Adding Melanie and Tomas to this thread. I noticed you both recently
committed similar changes to handle shared memory instrumentation
separation and retrieval for IndexScan/IndexOnlyScan (dd78e69cfc
<https://github.com/postgres/postgres/commit/dd78e69cfc337f93cfc0303ddf660262d7f1237e;)
and SeqScan (3b1117d6e2
<https://github.com/postgres/postgres/commit/3b1117d6e2e47d86cdbd978b79434c630cb0ef52;
).

My patch implements the exact same pattern for CustomScan states. It adds
an optional RetrieveInstrumentationCustomScan hook so that extensions can
aggregate their worker metrics before the DSM gets unlinked, bringing
custom scans to parity with the recent core scan instrumentation
improvements.

Could you please help review?

The CommitFest entry is also updated here:
https://commitfest.postgresql.org/patch/6524/

Thanks, Siddharth



On Tue, Jun 23, 2026 at 2:38 PM Siddharth Kothari <[email protected]> wrote:

> Hi hackers,
>
> Bumping this thread as this small patch is passing all CF checks but needs
> a reviewer.
>
> *The Problem:* Right now, if you write a parallel CustomScan extension,
> it is impossible to get performance metrics from parallel workers. The data
> is destroyed during DSM unlinking before the leader can grab it.
>
> *The Fix:* This patch adds an optional RetrieveInstrumentation hook to
> CustomExecMethods. It has zero overhead for existing extensions (it's a
> simple NULL check) but unlocks metric aggregation for parallel custom scans.
>
> Please let me know your thoughts.
>
> Thanks,
>
> Siddharth
>
> On Wed, Apr 8, 2026 at 10:57 AM Siddharth Kothari <[email protected]>
> wrote:
>
>> Hi everyone,
>>
>> I’m just checking in to see if anyone has had a chance to look at this or
>> if there’s any further information I should provide to help with the
>> review. I have also added the patch to PG20-1 CF queue, the link is
>> https://commitfest.postgresql.org/patch/6524/.
>>
>> Thanks,
>> Siddharth
>>
>> On Wed, Feb 18, 2026 at 3:09 PM Siddharth Kothari <[email protected]>
>> wrote:
>>
>>> 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
>>>
>>


Attachments:

  [application/x-patch] v2-0001-Add-RetrieveInstrumentationCustomScan-hook-for-Cu.patch (3.3K, ../CAGCUe0JRZP-=rOefQz0AYLPpeg=EN=a=TcD9=ZSDup1Mn+Sanw@mail.gmail.com/3-v2-0001-Add-RetrieveInstrumentationCustomScan-hook-for-Cu.patch)
  download | inline diff:
From 297ea1876dd6aa77ac59f1c9dbf5bd84eb726fb5 Mon Sep 17 00:00:00 2001
From: Siddharth Kothari <[email protected]>
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



view thread (8+ messages)  latest in thread

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected], [email protected], [email protected], [email protected], [email protected]
  Subject: Re: [PATCH] Add RetrieveInstrumentation hook for CustomScan providers
  In-Reply-To: <CAGCUe0JRZP-=rOefQz0AYLPpeg=EN=a=TcD9=ZSDup1Mn+Sanw@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox