summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndres Freund2018-11-13 20:18:25 +0000
committerAndres Freund2018-11-15 19:40:50 +0000
commitc058fc2a2b8ea25015b211186c88a6a3006f5937 (patch)
tree32c71bf0a7ce90d86c32b500bb2e27c6118d3dd3 /src
parent6a744413ea0c0c114348c4c010aa9f909c83d3f3 (diff)
Rationalize expression context reset in ExecModifyTable().
The current pattern of reseting expressions both in ExecProcessReturning() and ExecOnConflictUpdate() makes it harder than necessary to reason about memory lifetimes. It also requires materializing slots unnecessarily, although this patch doesn't take advantage of the fact that that's not necessary anymore. Instead reset the expression context once for each input tuple. Author: Ashutosh Bapat Discussion: https://postgr.es/m/[email protected]
Diffstat (limited to 'src')
-rw-r--r--src/backend/executor/nodeModifyTable.c22
1 files changed, 9 insertions, 13 deletions
diff --git a/src/backend/executor/nodeModifyTable.c b/src/backend/executor/nodeModifyTable.c
index e2836b75ff3..6ef694d5a4a 100644
--- a/src/backend/executor/nodeModifyTable.c
+++ b/src/backend/executor/nodeModifyTable.c
@@ -163,12 +163,6 @@ ExecProcessReturning(ResultRelInfo *resultRelInfo,
ProjectionInfo *projectReturning = resultRelInfo->ri_projectReturning;
ExprContext *econtext = projectReturning->pi_exprContext;
- /*
- * Reset per-tuple memory context to free any expression evaluation
- * storage allocated in the previous cycle.
- */
- ResetExprContext(econtext);
-
/* Make tuple and any needed join variables available to ExecProject */
if (tupleSlot)
econtext->ecxt_scantuple = tupleSlot;
@@ -1453,13 +1447,7 @@ ExecOnConflictUpdate(ModifyTableState *mtstate,
elog(ERROR, "unrecognized heap_lock_tuple status: %u", test);
}
- /*
- * Success, the tuple is locked.
- *
- * Reset per-tuple memory context to free any expression evaluation
- * storage allocated in the previous cycle.
- */
- ResetExprContext(econtext);
+ /* Success, the tuple is locked. */
/*
* Verify that the tuple is visible to our MVCC snapshot if the current
@@ -2028,6 +2016,14 @@ ExecModifyTable(PlanState *pstate)
*/
ResetPerTupleExprContext(estate);
+ /*
+ * Reset per-tuple memory context used for processing on conflict and
+ * returning clauses, to free any expression evaluation storage
+ * allocated in the previous cycle.
+ */
+ if (pstate->ps_ExprContext)
+ ResetExprContext(pstate->ps_ExprContext);
+
planSlot = ExecProcNode(subplanstate);
if (TupIsNull(planSlot))