diff --git a/src/backend/executor/execUtils.c b/src/backend/executor/execUtils.c index 4943339ebb..b74b0684b3 100644 --- a/src/backend/executor/execUtils.c +++ b/src/backend/executor/execUtils.c @@ -1348,10 +1348,25 @@ ExecGetExtraUpdatedCols(ResultRelInfo *relinfo, EState *estate) return NULL; } -/* Return columns being updated, including generated columns */ +/* + * Return columns being updated, including generated columns + * + * The bitmap is allocated in per-tuple memory context. It's up to the caller to + * copy it into a different context with the appropriate lifespan, if needed. + */ Bitmapset * ExecGetAllUpdatedCols(ResultRelInfo *relinfo, EState *estate) { - return bms_union(ExecGetUpdatedCols(relinfo, estate), - ExecGetExtraUpdatedCols(relinfo, estate)); + + Bitmapset *ret; + MemoryContext oldcxt; + + oldcxt = MemoryContextSwitchTo(GetPerTupleMemoryContext(estate)); + + ret = bms_union(ExecGetUpdatedCols(relinfo, estate), + ExecGetExtraUpdatedCols(relinfo, estate)); + + MemoryContextSwitchTo(oldcxt); + + return ret; }