Fwd: Per-tuple memory leak in 9.0 - Mailing list pgsql-bugs

From Dean Rasheed
Subject Fwd: Per-tuple memory leak in 9.0
Date
Msg-id AANLkTikcn82BNGRXO59krg=5=WpgYwe5OHBNc07xdQTq@mail.gmail.com
Whole thread Raw
List pgsql-bugs
Sorry, I meant to cc this to -bugs as well as -hackers


---------- Forwarded message ----------
From: Dean Rasheed <dean.a.rasheed@gmail.com>
Date: 18 August 2010 18:29
Subject: Per-tuple memory leak in 9.0
To: pgsql-hackers@postgresql.org


While testing triggers, I came across the following memory leak.
Here's a simple test case:

CREATE TABLE foo(a int);

CREATE OR REPLACE FUNCTION trig_fn() RETURNS trigger AS
$$
BEGIN
=A0RETURN NEW;
END;
$$
LANGUAGE plpgsql;

CREATE TRIGGER ins_trig BEFORE INSERT ON foo
=A0FOR EACH ROW EXECUTE PROCEDURE trig_fn();

INSERT INTO foo SELECT g
=A0FROM generate_series(1, 5000000) AS g;

Memory usage goes up by around 100 bytes per row for the duration of the qu=
ery.

The problem is that the trigger code assumes that anything it
allocates in the per-tuple memory context will be freed per-tuple
processed, which used to be the case because the loop in ExecutePlan()
calls ResetPerTupleExprContext() once each time round the loop, and
that used to correspond to once per tuple.

However, with the refactoring of that code out to nodeModifyTable.c,
this is no longer the case because the ModifyTable node processes all
the tuples from the subquery before returning, so I guess that the
loop in ExecModifyTable() needs to call ResetPerTupleExprContext()
each time round.

Regards,
Dean

pgsql-bugs by date:

Previous
From: Robert Haas
Date:
Subject: Re: BUG #5623: xml2 and uuid-ossp contribs fail to compile
Next
From: "Priya Kaliappan"
Date:
Subject: BUG #5624: Getting error while taking the backup of database from remote machine