diff --git a/src/backend/executor/execExpr.c b/src/backend/executor/execExpr.c index cd0dce150d6..97ec8fb033b 100644 --- a/src/backend/executor/execExpr.c +++ b/src/backend/executor/execExpr.c @@ -511,8 +511,12 @@ List * ExecPrepareExprList(List *nodes, EState *estate) { List *result = NIL; + MemoryContext oldcontext; ListCell *lc; + /* Ensure that the list cell nodes are in the right context too */ + oldcontext = MemoryContextSwitchTo(estate->es_query_cxt); + foreach(lc, nodes) { Expr *e = (Expr *) lfirst(lc); @@ -520,6 +524,8 @@ ExecPrepareExprList(List *nodes, EState *estate) result = lappend(result, ExecPrepareExpr(e, estate)); } + MemoryContextSwitchTo(oldcontext); + return result; }