Skip to content

Commit 538d114

Browse files
committed
Allow executor nodes to change their ExecProcNode function.
In order for executor nodes to be able to change their ExecProcNode function after ExecInitNode() has finished, provide ExecSetExecProcNode(). This allows any wrappers functions that only execProcnode.c knows about to be reinstalled. The motivation for wanting to change ExecProcNode after ExecInitNode() has finished is that it is not known until later whether parallel query is available, so if a parallel variant is to be installed then ExecInitNode() is too soon to decide. Author: Thomas Munro Reviewed-By: Andres Freund Discussion: https://postgr.es/m/CAEepm=09rr65VN+cAV5FgyM_z=D77Xy8Fuc9CDDDYbq3pQUezg@mail.gmail.com
1 parent dbb3d6f commit 538d114

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

src/backend/executor/execProcnode.c

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -370,12 +370,7 @@ ExecInitNode(Plan *node, EState *estate, int eflags)
370370
break;
371371
}
372372

373-
/*
374-
* Add a wrapper around the ExecProcNode callback that checks stack depth
375-
* during the first execution.
376-
*/
377-
result->ExecProcNodeReal = result->ExecProcNode;
378-
result->ExecProcNode = ExecProcNodeFirst;
373+
ExecSetExecProcNode(result, result->ExecProcNode);
379374

380375
/*
381376
* Initialize any initPlans present in this node. The planner put them in
@@ -401,6 +396,27 @@ ExecInitNode(Plan *node, EState *estate, int eflags)
401396
}
402397

403398

399+
/*
400+
* If a node wants to change its ExecProcNode function after ExecInitNode()
401+
* has finished, it should do so with this function. That way any wrapper
402+
* functions can be reinstalled, without the node having to know how that
403+
* works.
404+
*/
405+
void
406+
ExecSetExecProcNode(PlanState *node, ExecProcNodeMtd function)
407+
{
408+
/*
409+
* Add a wrapper around the ExecProcNode callback that checks stack depth
410+
* during the first execution and maybe adds an instrumentation
411+
* wrapper. When the callback is changed after execution has already begun
412+
* that means we'll superflously execute ExecProcNodeFirst, but that seems
413+
* ok.
414+
*/
415+
node->ExecProcNodeReal = function;
416+
node->ExecProcNode = ExecProcNodeFirst;
417+
}
418+
419+
404420
/*
405421
* ExecProcNode wrapper that performs some one-time checks, before calling
406422
* the relevant node method (possibly via an instrumentation wrapper).

src/include/executor/executor.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ extern void EvalPlanQualEnd(EPQState *epqstate);
219219
* functions in execProcnode.c
220220
*/
221221
extern PlanState *ExecInitNode(Plan *node, EState *estate, int eflags);
222+
extern void ExecSetExecProcNode(PlanState *node, ExecProcNodeMtd function);
222223
extern Node *MultiExecProcNode(PlanState *node);
223224
extern void ExecEndNode(PlanState *node);
224225
extern bool ExecShutdownNode(PlanState *node);

0 commit comments

Comments
 (0)