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

Commita1c2c43

Browse files
committed
Fix intra-query memory leakage in nodeProjectSet.c.
Both ExecMakeFunctionResultSet() and evaluation of simple expressionsneed to be done in the per-tuple memory context, not per-query, elsewe leak data until end of query. This is a consideration that wasmissed while refactoring code in the ProjectSet patch (note that inpre-v10, ExecMakeFunctionResult is called in the per-tuple context).Per bug #14843 from Ben M. Diagnosed independently by Andres and myself.Discussion:https://postgr.es/m/20171005230321.28561.15927@wrigleys.postgresql.org
1 parent6b87416 commita1c2c43

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

‎src/backend/executor/execSRF.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,8 @@ ExecInitFunctionResultSet(Expr *expr,
467467
* function itself. The argument expressions may not contain set-returning
468468
* functions (the planner is supposed to have separated evaluation for those).
469469
*
470+
* This should be called in a short-lived (per-tuple) context.
471+
*
470472
* This is used by nodeProjectSet.c.
471473
*/
472474
Datum

‎src/backend/executor/nodeProjectSet.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,12 +124,16 @@ ExecProjectSRF(ProjectSetState *node, bool continuing)
124124
{
125125
TupleTableSlot*resultSlot=node->ps.ps_ResultTupleSlot;
126126
ExprContext*econtext=node->ps.ps_ExprContext;
127+
MemoryContextoldcontext;
127128
boolhassrfPG_USED_FOR_ASSERTS_ONLY;
128129
boolhasresult;
129130
intargno;
130131

131132
ExecClearTuple(resultSlot);
132133

134+
/* Call SRFs, as well as plain expressions, in per-tuple context */
135+
oldcontext=MemoryContextSwitchTo(econtext->ecxt_per_tuple_memory);
136+
133137
/*
134138
* Assume no further tuples are produced unless an ExprMultipleResult is
135139
* encountered from a set returning function.
@@ -176,6 +180,8 @@ ExecProjectSRF(ProjectSetState *node, bool continuing)
176180
}
177181
}
178182

183+
MemoryContextSwitchTo(oldcontext);
184+
179185
/* ProjectSet should not be used if there's no SRFs */
180186
Assert(hassrf);
181187

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp