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

Commit7ab6971

Browse files
committed
Fix intra-query memory leak when a SRF returns zero rows.
When looping around after finding that the set-returning functionreturned zero rows for the current input tuple, ExecProjectSetneglected to reset either of the two memory contexts it'sresponsible for cleaning out. Typically this wouldn't cause muchproblem, because once the SRF does return at least one row, thecontexts would get reset on the next call. However, if the SRFreturns no rows for many input tuples in succession, quite a lotof memory could be transiently consumed.To fix, make sure we reset both contexts while looping around.Per bug #18172 from Sergei Kornilov. Back-patch to all supportedbranches.Discussion:https://postgr.es/m/18172-9b8c5fc1d676ded3@postgresql.org
1 parent64fc5e0 commit7ab6971

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

‎src/backend/executor/nodeProjectSet.c

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -72,20 +72,22 @@ ExecProjectSet(PlanState *pstate)
7272
returnresultSlot;
7373
}
7474

75-
/*
76-
* Reset argument context to free any expression evaluation storage
77-
* allocated in the previous tuple cycle. Note this can't happen until
78-
* we're done projecting out tuples from a scan tuple, as ValuePerCall
79-
* functions are allowed to reference the arguments for each returned
80-
* tuple.
81-
*/
82-
MemoryContextReset(node->argcontext);
83-
8475
/*
8576
* Get another input tuple and project SRFs from it.
8677
*/
8778
for (;;)
8879
{
80+
/*
81+
* Reset argument context to free any expression evaluation storage
82+
* allocated in the previous tuple cycle. Note this can't happen
83+
* until we're done projecting out tuples from a scan tuple, as
84+
* ValuePerCall functions are allowed to reference the arguments for
85+
* each returned tuple. However, if we loop around after finding that
86+
* no rows are produced from a scan tuple, we should reset, to avoid
87+
* leaking memory when many successive scan tuples produce no rows.
88+
*/
89+
MemoryContextReset(node->argcontext);
90+
8991
/*
9092
* Retrieve tuples from the outer plan until there are no more.
9193
*/
@@ -111,6 +113,12 @@ ExecProjectSet(PlanState *pstate)
111113
*/
112114
if (resultSlot)
113115
returnresultSlot;
116+
117+
/*
118+
* When we do loop back, we'd better reset the econtext again, just in
119+
* case the SRF leaked some memory there.
120+
*/
121+
ResetExprContext(econtext);
114122
}
115123

116124
returnNULL;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp