Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9f4992e

Browse files
committed
Remove memory leak protection from Gather and Gather Merge nodes.
Before commit6b65a7f, tqueue.c couldperform tuple remapping and thus leak memory, which is why commitaf33039 made TupleQueueReaderNextrun in a short-lived context. Now, however, tqueue.c has been reducedto a shadow of its former self, and there shouldn't be any chance ofleaks any more. Accordingly, remove some tuple copying and memorycontext manipulation to speed up processing.Patch by me, reviewed by Amit Kapila. Some testing by Rafia Sabih.Discussion:http://postgr.es/m/CAA4eK1LSDydwrNjmYSNkfJ3ZivGSWH9SVswh6QpNzsMdj_oOQA@mail.gmail.com
1 parenta852cfe commit9f4992e

File tree

3 files changed

+5
-21
lines changed

3 files changed

+5
-21
lines changed

‎src/backend/executor/nodeGather.c

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@ static TupleTableSlot *
131131
ExecGather(PlanState*pstate)
132132
{
133133
GatherState*node=castNode(GatherState,pstate);
134-
TupleTableSlot*fslot=node->funnel_slot;
135134
TupleTableSlot*slot;
136135
ExprContext*econtext;
137136

@@ -205,11 +204,8 @@ ExecGather(PlanState *pstate)
205204

206205
/*
207206
* Reset per-tuple memory context to free any expression evaluation
208-
* storage allocated in the previous tuple cycle. This will also clear
209-
* any previous tuple returned by a TupleQueueReader; to make sure we
210-
* don't leave a dangling pointer around, clear the working slot first.
207+
* storage allocated in the previous tuple cycle.
211208
*/
212-
ExecClearTuple(fslot);
213209
econtext=node->ps.ps_ExprContext;
214210
ResetExprContext(econtext);
215211

@@ -258,7 +254,6 @@ gather_getnext(GatherState *gatherstate)
258254
PlanState*outerPlan=outerPlanState(gatherstate);
259255
TupleTableSlot*outerTupleSlot;
260256
TupleTableSlot*fslot=gatherstate->funnel_slot;
261-
MemoryContexttupleContext=gatherstate->ps.ps_ExprContext->ecxt_per_tuple_memory;
262257
HeapTupletup;
263258

264259
while (gatherstate->nreaders>0||gatherstate->need_to_scan_locally)
@@ -267,20 +262,15 @@ gather_getnext(GatherState *gatherstate)
267262

268263
if (gatherstate->nreaders>0)
269264
{
270-
MemoryContextoldContext;
271-
272-
/* Run TupleQueueReaders in per-tuple context */
273-
oldContext=MemoryContextSwitchTo(tupleContext);
274265
tup=gather_readnext(gatherstate);
275-
MemoryContextSwitchTo(oldContext);
276266

277267
if (HeapTupleIsValid(tup))
278268
{
279269
ExecStoreTuple(tup,/* tuple to store */
280270
fslot,/* slot in which to store the tuple */
281271
InvalidBuffer,/* buffer associated with this
282272
* tuple */
283-
false);/*slot should not pfree tuple */
273+
true);/*pfree tuple when done with it */
284274
returnfslot;
285275
}
286276
}

‎src/backend/executor/nodeGatherMerge.c

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,7 @@ load_tuple_array(GatherMergeState *gm_state, int reader)
609609
&tuple_buffer->done);
610610
if (!HeapTupleIsValid(tuple))
611611
break;
612-
tuple_buffer->tuple[i]=heap_copytuple(tuple);
612+
tuple_buffer->tuple[i]=tuple;
613613
tuple_buffer->nTuples++;
614614
}
615615
}
@@ -673,7 +673,6 @@ gather_merge_readnext(GatherMergeState *gm_state, int reader, bool nowait)
673673
&tuple_buffer->done);
674674
if (!HeapTupleIsValid(tup))
675675
return false;
676-
tup=heap_copytuple(tup);
677676

678677
/*
679678
* Attempt to read more tuples in nowait mode and store them in the
@@ -703,20 +702,13 @@ gm_readnext_tuple(GatherMergeState *gm_state, int nreader, bool nowait,
703702
{
704703
TupleQueueReader*reader;
705704
HeapTupletup;
706-
MemoryContextoldContext;
707-
MemoryContexttupleContext;
708705

709706
/* Check for async events, particularly messages from workers. */
710707
CHECK_FOR_INTERRUPTS();
711708

712709
/* Attempt to read a tuple. */
713710
reader=gm_state->reader[nreader-1];
714-
715-
/* Run TupleQueueReaders in per-tuple context */
716-
tupleContext=gm_state->ps.ps_ExprContext->ecxt_per_tuple_memory;
717-
oldContext=MemoryContextSwitchTo(tupleContext);
718711
tup=TupleQueueReaderNext(reader,nowait,done);
719-
MemoryContextSwitchTo(oldContext);
720712

721713
returntup;
722714
}

‎src/backend/executor/tqueue.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,8 @@ DestroyTupleQueueReader(TupleQueueReader *reader)
161161
* is set to true when there are no remaining tuples and otherwise to false.
162162
*
163163
* The returned tuple, if any, is allocated in CurrentMemoryContext.
164+
* Note that this routine must not leak memory! (We used to allow that,
165+
* but not any more.)
164166
*
165167
* Even when shm_mq_receive() returns SHM_MQ_WOULD_BLOCK, this can still
166168
* accumulate bytes from a partially-read message, so it's useful to call

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp