]> granicus.if.org Git - postgresql/commitdiff
Allow executor nodes to change their ExecProcNode function.
authorAndres Freund <andres@anarazel.de>
Wed, 13 Dec 2017 23:47:01 +0000 (15:47 -0800)
committerAndres Freund <andres@anarazel.de>
Wed, 13 Dec 2017 23:47:01 +0000 (15:47 -0800)
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

src/backend/executor/execProcnode.c
src/include/executor/executor.h

index 9befca901615cbd9234c60f1761e178d68595c44..fcb8b56999902bb6508ec25714ef03a06a610d51 100644 (file)
@@ -370,12 +370,7 @@ ExecInitNode(Plan *node, EState *estate, int eflags)
                        break;
        }
 
-       /*
-        * Add a wrapper around the ExecProcNode callback that checks stack depth
-        * during the first execution.
-        */
-       result->ExecProcNodeReal = result->ExecProcNode;
-       result->ExecProcNode = ExecProcNodeFirst;
+       ExecSetExecProcNode(result, result->ExecProcNode);
 
        /*
         * Initialize any initPlans present in this node.  The planner put them in
@@ -401,6 +396,27 @@ ExecInitNode(Plan *node, EState *estate, int eflags)
 }
 
 
+/*
+ * If a node wants to change its ExecProcNode function after ExecInitNode()
+ * has finished, it should do so with this function.  That way any wrapper
+ * functions can be reinstalled, without the node having to know how that
+ * works.
+ */
+void
+ExecSetExecProcNode(PlanState *node, ExecProcNodeMtd function)
+{
+       /*
+        * Add a wrapper around the ExecProcNode callback that checks stack depth
+        * during the first execution and maybe adds an instrumentation
+        * wrapper. When the callback is changed after execution has already begun
+        * that means we'll superflously execute ExecProcNodeFirst, but that seems
+        * ok.
+        */
+       node->ExecProcNodeReal = function;
+       node->ExecProcNode = ExecProcNodeFirst;
+}
+
+
 /*
  * ExecProcNode wrapper that performs some one-time checks, before calling
  * the relevant node method (possibly via an instrumentation wrapper).
index b5578f5855feba3c549fe9aef0706d1989f3bc8a..dea9216fd62b2bfffbb7fc36409624bf642bfb15 100644 (file)
@@ -219,6 +219,7 @@ extern void EvalPlanQualEnd(EPQState *epqstate);
  * functions in execProcnode.c
  */
 extern PlanState *ExecInitNode(Plan *node, EState *estate, int eflags);
+extern void ExecSetExecProcNode(PlanState *node, ExecProcNodeMtd function);
 extern Node *MultiExecProcNode(PlanState *node);
 extern void ExecEndNode(PlanState *node);
 extern bool ExecShutdownNode(PlanState *node);