From f0f4766679abcd55fbb117abfc97ccebf0522c80 Mon Sep 17 00:00:00 2001
From: Andres Freund <andres@anarazel.de>
Date: Thu, 31 Aug 2017 13:27:28 -0700
Subject: [PATCH 07/16] Pass through PlanState parent to expression
 instantiation.

---
 src/backend/executor/execExpr.c       | 21 +++++++++++++++------
 src/backend/executor/execExprInterp.c |  2 +-
 2 files changed, 16 insertions(+), 7 deletions(-)

diff --git a/src/backend/executor/execExpr.c b/src/backend/executor/execExpr.c
index 81549ee915..b5bde3fa80 100644
--- a/src/backend/executor/execExpr.c
+++ b/src/backend/executor/execExpr.c
@@ -54,7 +54,7 @@ typedef struct LastAttnumInfo
 	AttrNumber	last_scan;
 } LastAttnumInfo;
 
-static void ExecReadyExpr(ExprState *state);
+static void ExecReadyExpr(ExprState *state, PlanState *parent);
 static void ExecInitExprRec(Expr *node, PlanState *parent, ExprState *state,
 				Datum *resv, bool *resnull);
 static void ExprEvalPushStep(ExprState *es, const ExprEvalStep *s);
@@ -123,6 +123,9 @@ ExecInitExpr(Expr *node, PlanState *parent)
 	state = makeNode(ExprState);
 	state->expr = node;
 
+	scratch.resvalue = NULL;
+	scratch.resnull = NULL;
+
 	/* Insert EEOP_*_FETCHSOME steps as needed */
 	ExecInitExprSlots(state, (Node *) node);
 
@@ -133,7 +136,7 @@ ExecInitExpr(Expr *node, PlanState *parent)
 	scratch.opcode = EEOP_DONE;
 	ExprEvalPushStep(state, &scratch);
 
-	ExecReadyExpr(state);
+	ExecReadyExpr(state, parent);
 
 	return state;
 }
@@ -225,7 +228,7 @@ ExecInitQual(List *qual, PlanState *parent)
 	scratch.opcode = EEOP_DONE;
 	ExprEvalPushStep(state, &scratch);
 
-	ExecReadyExpr(state);
+	ExecReadyExpr(state, parent);
 
 	return state;
 }
@@ -316,6 +319,9 @@ ExecBuildProjectionInfo(List *targetList,
 	state->expr = (Expr *) targetList;
 	state->resultslot = slot;
 
+	scratch.resvalue = NULL;
+	scratch.resnull = NULL;
+
 	/* Insert EEOP_*_FETCHSOME steps as needed */
 	ExecInitExprSlots(state, (Node *) targetList);
 
@@ -417,7 +423,7 @@ ExecBuildProjectionInfo(List *targetList,
 	scratch.opcode = EEOP_DONE;
 	ExprEvalPushStep(state, &scratch);
 
-	ExecReadyExpr(state);
+	ExecReadyExpr(state, parent);
 
 	return projInfo;
 }
@@ -571,9 +577,9 @@ ExecCheck(ExprState *state, ExprContext *econtext)
  * ExecReadyInterpretedExpr().
  */
 static void
-ExecReadyExpr(ExprState *state)
+ExecReadyExpr(ExprState *state, PlanState *parent)
 {
-	ExecReadyInterpretedExpr(state);
+	ExecReadyInterpretedExpr(state, parent);
 }
 
 /*
@@ -2173,6 +2179,9 @@ ExecInitExprSlots(ExprState *state, Node *node)
 	LastAttnumInfo info = {0, 0, 0};
 	ExprEvalStep scratch;
 
+	scratch.resvalue = NULL;
+	scratch.resnull = NULL;
+
 	/*
 	 * Figure out which attributes we're going to need.
 	 */
diff --git a/src/backend/executor/execExprInterp.c b/src/backend/executor/execExprInterp.c
index 50e3f8b176..df453b2ab4 100644
--- a/src/backend/executor/execExprInterp.c
+++ b/src/backend/executor/execExprInterp.c
@@ -151,7 +151,7 @@ static Datum ExecJustAssignScanVar(ExprState *state, ExprContext *econtext, bool
  * Prepare ExprState for interpreted execution.
  */
 void
-ExecReadyInterpretedExpr(ExprState *state)
+ExecReadyInterpretedExpr(ExprState *state, PlanState *parent)
 {
 	/* Ensure one-time interpreter setup has been done */
 	ExecInitInterpreter();
-- 
2.14.1.2.g4274c698f4.dirty

