pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Craig Ringer <craig@2ndquadrant.com>
Cc: PostgreSQL Hackers <pgsql-hackers@postgresql.org>
Subject: Re: Curing plpgsql's memory leaks for statement-lifespan values
Date: Fri, 22 Jul 2016 10:52:35 -0400
Message-ID: <22248.1469199155@sss.pgh.pa.us> (raw)
In-Reply-To: <CAMsr+YEC5dQFsqWgFJhqZT_gs33z9-_2yASyGL+Z9XdHOQ=+JQ@mail.gmail.com>
References: <17863.1469142152@sss.pgh.pa.us>
	<CAMsr+YGwc0xte1wp_aqBFiWbXvf=tEG4U-JC8yZWSzsjQv5-Ug@mail.gmail.com>
	<CAMsr+YEC5dQFsqWgFJhqZT_gs33z9-_2yASyGL+Z9XdHOQ=+JQ@mail.gmail.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-hackers>

Craig Ringer <craig@2ndquadrant.com> writes:
> On 22 July 2016 at 13:24, Craig Ringer <craig@2ndquadrant.com> wrote:
>> I suggest that in cassert builds, or maybe just CACHE_CLOBBER_ALWAYS, the
>> context is reset after each call even when not cleaning up after an error.
>> That'll help catch mistakes and leaks.

> That is, after each statement.

Well, the issue is with nested statements: if some outer statement has
data in such a context, you can't just clobber it because of a failure in
an inner statement.  To make that work, you need a new context for each
nesting level.  Once we've gone to that much trouble, I'm inclined to
think we should just do the resets always (ie, not only in debug builds).
That will let us get rid of retail pfree's and buy back at least some of
the added cost.

I've not done any detail work on this idea yet, but at least some of
plpgsql's loop control statements don't have any pass-by-ref local data;
exec_stmt_fori, for example.  So it seems possible for that function not
to bother with creating a new context for its child statements.  That
would save some more cycles, at the cost of a possibly-confusing-and-
fragile difference in the way different kinds of loops work.

In any case, I'm thinking this is too invasive, relative to its value,
for a back-patch; but it might be okay to sneak it into beta4 if I can
get it done soon.  Or we could let it slide till 9.7^H^H^H10.  Comments?

			regards, tom lane


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers



view thread (20+ messages)  latest in thread

Message-ID: <22248.1469199155@sss.pgh.pa.us>
Permalink:  ../22248.1469199155@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/22248.1469199155@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-hackers@postgresql.org
  Cc: tgl@sss.pgh.pa.us, craig@2ndquadrant.com
  Subject: Re: Curing plpgsql's memory leaks for statement-lifespan values
  In-Reply-To: <22248.1469199155@sss.pgh.pa.us>
  References: <17863.1469142152@sss.pgh.pa.us> <CAMsr+YGwc0xte1wp_aqBFiWbXvf=tEG4U-JC8yZWSzsjQv5-Ug@mail.gmail.com> <CAMsr+YEC5dQFsqWgFJhqZT_gs33z9-_2yASyGL+Z9XdHOQ=+JQ@mail.gmail.com> <22248.1469199155@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox