1
0
mirror of https://github.com/postgres/postgres.git synced 2025-04-27 22:56:53 +03:00

Support for custom slots in the custom executor nodes

Some custom table access method may have their tuple format and use custom
executor nodes for their custom scan types. The ability to set a custom slot
would save them from tuple format conversion. Other users of custom executor
nodes may also benefit.

Discussion: https://postgr.es/m/CAPpHfduJUU6ToecvTyRE_yjxTS80FyPpct4OHaLFk3OEheMTNA@mail.gmail.com
Author: Alexander Korotkov
Reviewed-by: Pavel Borisov
This commit is contained in:
Alexander Korotkov 2022-11-24 00:36:11 +03:00
parent b7a5ef17cf
commit cee1209514
2 changed files with 12 additions and 2 deletions

View File

@ -29,6 +29,7 @@ CustomScanState *
ExecInitCustomScan(CustomScan *cscan, EState *estate, int eflags) ExecInitCustomScan(CustomScan *cscan, EState *estate, int eflags)
{ {
CustomScanState *css; CustomScanState *css;
const TupleTableSlotOps *slotOps;
Relation scan_rel = NULL; Relation scan_rel = NULL;
Index scanrelid = cscan->scan.scanrelid; Index scanrelid = cscan->scan.scanrelid;
int tlistvarno; int tlistvarno;
@ -63,6 +64,14 @@ ExecInitCustomScan(CustomScan *cscan, EState *estate, int eflags)
css->ss.ss_currentRelation = scan_rel; 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 * Determine the scan tuple type. If the custom scan provider provided a
* targetlist describing the scan tuples, use that; else use base * targetlist describing the scan tuples, use that; else use base
@ -73,14 +82,14 @@ ExecInitCustomScan(CustomScan *cscan, EState *estate, int eflags)
TupleDesc scan_tupdesc; TupleDesc scan_tupdesc;
scan_tupdesc = ExecTypeFromTL(cscan->custom_scan_tlist); 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 */ /* Node's targetlist will contain Vars with varno = INDEX_VAR */
tlistvarno = INDEX_VAR; tlistvarno = INDEX_VAR;
} }
else else
{ {
ExecInitScanTupleSlot(estate, &css->ss, RelationGetDescr(scan_rel), ExecInitScanTupleSlot(estate, &css->ss, RelationGetDescr(scan_rel),
&TTSOpsVirtual); slotOps);
/* Node's targetlist will contain Vars with varno = scanrelid */ /* Node's targetlist will contain Vars with varno = scanrelid */
tlistvarno = scanrelid; tlistvarno = scanrelid;
} }

View File

@ -1949,6 +1949,7 @@ typedef struct CustomScanState
List *custom_ps; /* list of child PlanState nodes, if any */ List *custom_ps; /* list of child PlanState nodes, if any */
Size pscan_len; /* size of parallel coordination information */ Size pscan_len; /* size of parallel coordination information */
const struct CustomExecMethods *methods; const struct CustomExecMethods *methods;
const struct TupleTableSlotOps *slotOps;
} CustomScanState; } CustomScanState;
/* ---------------------------------------------------------------- /* ----------------------------------------------------------------