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

Commitf245236

Browse files
committed
Use per-tuple context in ExecGetAllUpdatedCols
Commitfc22b66 (generated columns) replaced ExecGetUpdatedCols() withExecGetAllUpdatedCols() in a couple places handling UPDATE (triggers andlock mode). However, ExecGetUpdatedCols() did exec_rt_fetch() whileExecGetAllUpdatedCols() also allocates memory through bms_union()without paying attention to the memory context and happened to use thelong-lived ExecutorState, leaking the memory until the end of the query.The amount of leaked memory is proportional to the number of (updated)attributes, types of UPDATE triggers, and the number of processed rows(which for UPDATE ... FROM ... may be much higher than updated rows).Fixed by switching to the per-tuple context in GetAllUpdatedColumns().This is fine for all in-core callers, but external callers may need tocopy the result. But we're not aware of any such callers.Note the issue was introduced byfc22b66, but the macros were laterrenamed byf50e888.Backpatch to 12, where the issue was introduced.Reported-by: Tomas VondraReviewed-by: Andres Freund, Tom Lane, Jakub WartakBackpatch-through: 12Discussion:https://postgr.es/m/222a3442-7f7d-246c-ed9b-a76209d19239@enterprisedb.com
1 parentfb5a7d8 commitf245236

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

‎src/backend/executor/execUtils.c

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1345,12 +1345,26 @@ ExecGetExtraUpdatedCols(ResultRelInfo *relinfo, EState *estate)
13451345
returnrelinfo->ri_extraUpdatedCols;
13461346
}
13471347

1348-
/* Return columns being updated, including generated columns */
1348+
/*
1349+
* Return columns being updated, including generated columns
1350+
*
1351+
* The bitmap is allocated in per-tuple memory context. It's up to the caller to
1352+
* copy it into a different context with the appropriate lifespan, if needed.
1353+
*/
13491354
Bitmapset*
13501355
ExecGetAllUpdatedCols(ResultRelInfo*relinfo,EState*estate)
13511356
{
1352-
returnbms_union(ExecGetUpdatedCols(relinfo,estate),
1353-
ExecGetExtraUpdatedCols(relinfo,estate));
1357+
Bitmapset*ret;
1358+
MemoryContextoldcxt;
1359+
1360+
oldcxt=MemoryContextSwitchTo(GetPerTupleMemoryContext(estate));
1361+
1362+
ret=bms_union(ExecGetUpdatedCols(relinfo,estate),
1363+
ExecGetExtraUpdatedCols(relinfo,estate));
1364+
1365+
MemoryContextSwitchTo(oldcxt);
1366+
1367+
returnret;
13541368
}
13551369

13561370
/*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp