[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pgsql-hackers
Subject:    [PATCH] Allow specification of custom slot for custom nodes
From:       Alexander Korotkov <aekorotkov () gmail ! com>
Date:       2022-06-30 19:41:10
Message-ID: CAPpHfduJUU6ToecvTyRE_yjxTS80FyPpct4OHaLFk3OEheMTNA () mail ! gmail ! com
[Download RAW message or body]

Hackers,

we have supported custom nodes for while. Custom slots are a bit more
"recent" feature. Since we now support custom slots, which could
handle custom tuple format, why not allow custom nodes to use them?

For instance, a custom table access method can have its own tuple
format and use a custom node to provide some custom type of scan. The
ability to set a custom slot would save us from tuple format
conversion (thank happened to me while working on OrioleDB). I think
other users of custom nodes may also benefit.

------
Regards,
Alexander Korotkov

["0001-Allow-specification-of-custom-slot-for-custom-nod-v1.patch" (application/octet-stream)]

From d9fe25cd6806315894097b83929eeedaae4f2db0 Mon Sep 17 00:00:00 2001
From: Alexander Korotkov <akorotkov@postgresql.org>
Date: Thu, 30 Jun 2022 22:33:18 +0300
Subject: [PATCH] Allow specification of custom slot for custom nodes

---
 src/backend/executor/nodeCustom.c | 13 +++++++++++--
 src/include/nodes/execnodes.h     |  1 +
 2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/src/backend/executor/nodeCustom.c b/src/backend/executor/nodeCustom.c
index 8f56bd8a23a..a76ec43b9fe 100644
--- a/src/backend/executor/nodeCustom.c
+++ b/src/backend/executor/nodeCustom.c
@@ -29,6 +29,7 @@ CustomScanState *
 ExecInitCustomScan(CustomScan *cscan, EState *estate, int eflags)
 {
 	CustomScanState *css;
+	const TupleTableSlotOps *slotOps;
 	Relation	scan_rel = NULL;
 	Index		scanrelid = cscan->scan.scanrelid;
 	int			tlistvarno;
@@ -63,6 +64,14 @@ ExecInitCustomScan(CustomScan *cscan, EState *estate, int eflags)
 		css->ss.ss_currentRelation = scan_rel;
 	}
 
+	/*
+	 * Use a custom slot if specified in CustomScanState or use virtual slot
+	 * otherwise.
+	 */
+	slotOps = css->slotOps;
+	if (!slotOps)
+		slotOps = &TTSOpsVirtual;
+
 	/*
 	 * Determine the scan tuple type.  If the custom scan provider provided a
 	 * targetlist describing the scan tuples, use that; else use base
@@ -73,14 +82,14 @@ ExecInitCustomScan(CustomScan *cscan, EState *estate, int eflags)
 		TupleDesc	scan_tupdesc;
 
 		scan_tupdesc = ExecTypeFromTL(cscan->custom_scan_tlist);
-		ExecInitScanTupleSlot(estate, &css->ss, scan_tupdesc, &TTSOpsVirtual);
+		ExecInitScanTupleSlot(estate, &css->ss, scan_tupdesc, slotOps);
 		/* Node's targetlist will contain Vars with varno = INDEX_VAR */
 		tlistvarno = INDEX_VAR;
 	}
 	else
 	{
 		ExecInitScanTupleSlot(estate, &css->ss, RelationGetDescr(scan_rel),
-							  &TTSOpsVirtual);
+							  slotOps);
 		/* Node's targetlist will contain Vars with varno = scanrelid */
 		tlistvarno = scanrelid;
 	}
diff --git a/src/include/nodes/execnodes.h b/src/include/nodes/execnodes.h
index 57288013795..2eebf60c8c3 100644
--- a/src/include/nodes/execnodes.h
+++ b/src/include/nodes/execnodes.h
@@ -1932,6 +1932,7 @@ typedef struct CustomScanState
 	List	   *custom_ps;		/* list of child PlanState nodes, if any */
 	Size		pscan_len;		/* size of parallel coordination information */
 	const struct CustomExecMethods *methods;
+	const struct TupleTableSlotOps *slotOps;
 } CustomScanState;
 
 /* ----------------------------------------------------------------
-- 
2.24.3 (Apple Git-128)



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic