Fix memory leak during long distributed insert

Tuple expression context memory context is not properly
reset during chunk dispatch execution which eventually
consumes all available memory during the query execution:

INSERT INTO test_table
  SELECT now() - random() * interval '2 years', (i/100)::text, random()
FROM
  generate_series(1,700000) AS sub(i);

This problem does not reproduces for a distributed hypertables
with disabled batching and for a regular hypertables.
Because luckly the tuple expression context got freed during
the ModifyTable node execution.
This commit is contained in:
Dmitry Simonenko 2019-12-10 16:42:34 +03:00 committed by Erik Nordström
parent 71e2c35d48
commit 6f5da9b5eb

View File

@ -116,6 +116,9 @@ chunk_dispatch_exec(CustomScanState *node)
if (TupIsNull(slot))
return NULL;
/* Reset the per-tuple exprcontext */
ResetPerTupleExprContext(estate);
/* Switch to the executor's per-tuple memory context */
old = MemoryContextSwitchTo(GetPerTupleMemoryContext(estate));