pgsql: ALTER TABLE ADD COLUMN exhibits a significant memory leak when

Поиск
Список
Период
Сортировка
От neilc@svr1.postgresql.org (Neil Conway)
Тема pgsql: ALTER TABLE ADD COLUMN exhibits a significant memory leak when
Дата
Msg-id 20050209232745.CAE778BA092@svr1.postgresql.org
обсуждение исходный текст
Список pgsql-committers
Log Message:
-----------
ALTER TABLE ADD COLUMN exhibits a significant memory leak when adding a
column with a default expression. In that situation, we need to rewrite
the heap relation. To evaluate the new default expression, we use
ExecEvalExpr(); however, this can allocate memory in the current memory
context, and ATRewriteTable() does not switch out of the active portal's
heap memory context. The end result is a rather large memory leak (on
the order of gigabytes for a reasonably sized table).

This patch changes ATRewriteTable() to switch to the per-tuple memory
context before beginning the per-tuple loop. It also removes an explicit
heap_freetuple() in the loop, since that is no longer needed.

In an unrelated change, I noticed the code was scanning through the
attributes of the new tuple descriptor for each tuple of the old table.
I changed this to use precomputation, which should slightly speed up
the loop.

Thanks to steve@deefs.net for reporting the leak.

Tags:
----
REL8_0_STABLE

Modified Files:
--------------
    pgsql/src/backend/commands:
        tablecmds.c (r1.142.4.1 -> r1.142.4.2)

(http://developer.postgresql.org/cvsweb.cgi/pgsql/src/backend/commands/tablecmds.c.diff?r1=1.142.4.1&r2=1.142.4.2)

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

Предыдущее
От: neilc@svr1.postgresql.org (Neil Conway)
Дата:
Сообщение: pgsql: ALTER TABLE ADD COLUMN exhibits a significant memory leak when
Следующее
От: tfavier@pgfoundry.org (User Tfavier)
Дата:
Сообщение: pqa - pqa: Added WARNING/FATAL/PANIC errors Those are now taken into