pgsql: Use per-tuple context in ExecGetAllUpdatedCols

Поиск
Список
Период
Сортировка
От Tomas Vondra
Тема pgsql: Use per-tuple context in ExecGetAllUpdatedCols
Дата
Msg-id E1q6wS6-000dLP-AJ@gemulon.postgresql.org
обсуждение исходный текст
Список pgsql-committers
Use per-tuple context in ExecGetAllUpdatedCols

Commit fc22b6623b (generated columns) replaced ExecGetUpdatedCols() with
ExecGetAllUpdatedCols() in a couple places handling UPDATE (triggers and
lock mode). However, ExecGetUpdatedCols() did exec_rt_fetch() while
ExecGetAllUpdatedCols() also allocates memory through bms_union()
without paying attention to the memory context and happened to use the
long-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 to
copy the result. But we're not aware of any such callers.

Note the issue was introduced by fc22b6623b, but the macros were later
renamed by f50e888990.

Backpatch to 12, where the issue was introduced.

Reported-by: Tomas Vondra
Reviewed-by: Andres Freund, Tom Lane, Jakub Wartak
Backpatch-through: 12
Discussion: https://postgr.es/m/222a3442-7f7d-246c-ed9b-a76209d19239@enterprisedb.com

Branch
------
REL_15_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/ee87f8b63aee39673d014e4ee9a1293b0b45d113

Modified Files
--------------
src/backend/executor/execUtils.c | 21 ++++++++++++++++++---
1 file changed, 18 insertions(+), 3 deletions(-)


В списке pgsql-committers по дате отправления:

Предыдущее
От: Tomas Vondra
Дата:
Сообщение: pgsql: Use per-tuple context in ExecGetAllUpdatedCols
Следующее
От: Tomas Vondra
Дата:
Сообщение: pgsql: Use per-tuple context in ExecGetAllUpdatedCols