diff --git a/src/backend/access/gin/gininsert.c b/src/backend/access/gin/gininsert.c index a7b7b5996e32..485513b11fb4 100644 --- a/src/backend/access/gin/gininsert.c +++ b/src/backend/access/gin/gininsert.c @@ -1616,6 +1616,7 @@ _gin_parallel_merge(GinBuildState *state) Size tuplen; double reltuples = 0; GinBuffer *buffer; + MemoryContext oldCtx; /* GIN tuples from workers, merged by leader */ double numtuples = 0; @@ -1685,9 +1686,12 @@ _gin_parallel_merge(GinBuildState *state) */ AssertCheckItemPointers(buffer); + oldCtx = MemoryContextSwitchTo(state->tmpCtx); ginEntryInsert(&state->ginstate, buffer->attnum, buffer->key, buffer->category, buffer->items, buffer->nitems, &state->buildStats); + MemoryContextSwitchTo(oldCtx); + MemoryContextReset(state->tmpCtx); /* discard the existing data */ GinBufferReset(buffer); @@ -1711,9 +1715,12 @@ _gin_parallel_merge(GinBuildState *state) */ AssertCheckItemPointers(buffer); + oldCtx = MemoryContextSwitchTo(state->tmpCtx); ginEntryInsert(&state->ginstate, buffer->attnum, buffer->key, buffer->category, buffer->items, buffer->nfrozen, &state->buildStats); + MemoryContextSwitchTo(oldCtx); + MemoryContextReset(state->tmpCtx); /* truncate the data we've just discarded */ GinBufferTrim(buffer);