diff --git a/src/backend/executor/execSRF.c b/src/backend/executor/execSRF.c index 8bc90a6c7e8..1be683db83d 100644 --- a/src/backend/executor/execSRF.c +++ b/src/backend/executor/execSRF.c @@ -467,6 +467,8 @@ ExecInitFunctionResultSet(Expr *expr, * function itself. The argument expressions may not contain set-returning * functions (the planner is supposed to have separated evaluation for those). * + * This should be called in a short-lived (per-tuple) context. + * * This is used by nodeProjectSet.c. */ Datum diff --git a/src/backend/executor/nodeProjectSet.c b/src/backend/executor/nodeProjectSet.c index d93462c5421..68981296f90 100644 --- a/src/backend/executor/nodeProjectSet.c +++ b/src/backend/executor/nodeProjectSet.c @@ -124,12 +124,16 @@ ExecProjectSRF(ProjectSetState *node, bool continuing) { TupleTableSlot *resultSlot = node->ps.ps_ResultTupleSlot; ExprContext *econtext = node->ps.ps_ExprContext; + MemoryContext oldcontext; bool hassrf PG_USED_FOR_ASSERTS_ONLY; bool hasresult; int argno; ExecClearTuple(resultSlot); + /* Call SRFs, as well as plain expressions, in per-tuple context */ + oldcontext = MemoryContextSwitchTo(econtext->ecxt_per_tuple_memory); + /* * Assume no further tuples are produced unless an ExprMultipleResult is * encountered from a set returning function. @@ -176,6 +180,8 @@ ExecProjectSRF(ProjectSetState *node, bool continuing) } } + MemoryContextSwitchTo(oldcontext); + /* ProjectSet should not be used if there's no SRFs */ Assert(hassrf);