Skip site navigation (1) Skip section navigation (2)

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

From: neilc(at)svr1(dot)postgresql(dot)org (Neil Conway)
To: pgsql-committers(at)postgresql(dot)org
Subject: pgsql: ALTER TABLE ADD COLUMN exhibits a significant memory leak when
Date: 2005-02-09 23:17:33
Message-ID: 20050209231733.0E49E8BA0FD@svr1.postgresql.org (view raw or flat)
Thread:
Lists: 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(at)deefs(dot)net for reporting the leak.

Modified Files:
--------------
    pgsql/src/backend/commands:
        tablecmds.c (r1.145 -> r1.146)
        (http://developer.postgresql.org/cvsweb.cgi/pgsql/src/backend/commands/tablecmds.c.diff?r1=1.145&r2=1.146)

pgsql-committers by date

Next:From: Neil ConwayDate: 2005-02-09 23:27:45
Subject: pgsql: ALTER TABLE ADD COLUMN exhibits a significant memory leak when
Previous:From: Michael MeskesDate: 2005-02-09 11:28:22
Subject: pgsql: Fixed bug in parsing of CREATE AS statement.

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group