From: Tom Lane <tgl@sss.pgh.pa.us>
To: Robert Haas <robertmhaas@gmail.com>
Cc: Alvaro Herrera <alvherre@2ndquadrant.com>
Cc: Amit Kapila <amit.kapila16@gmail.com>
Cc: pgsql-hackers <pgsql-hackers@postgresql.org>
Subject: Re: Curing plpgsql's memory leaks for statement-lifespan values
Date: Wed, 27 Jul 2016 10:49:51 -0400
Message-ID: <6969.1469630991@sss.pgh.pa.us> (raw)
In-Reply-To: <CA+TgmoYdovO69cEtd0UnYs57juSDN4gFX_+fe73P9TihS3gf2w@mail.gmail.com>
References: <20160725211919.GA298355@alvherre.pgsql>
<619.1469484240@sss.pgh.pa.us>
<CA+TgmoYdovO69cEtd0UnYs57juSDN4gFX_+fe73P9TihS3gf2w@mail.gmail.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-hackers>
Robert Haas <robertmhaas@gmail.com> writes:
> On Mon, Jul 25, 2016 at 6:04 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
>> I suppose that a fix based on putting PG_TRY blocks into all the affected
>> functions might be simple enough that we'd risk back-patching it, but
>> I don't really want to go that way.
> try/catch blocks aren't completely free, either, and PL/pgsql is not
> suffering from a deplorable excess of execution speed.
BTW, just to annotate that a bit: I did some measurements and found out
that on my Linux box, creating/deleting a memory context
(AllocSetContextCreate + MemoryContextDelete) is somewhere around 10x
more expensive than a PG_TRY block. This means that the PG_TRY approach
would actually be faster for cases involving only a small number of
statements-needing-local-storage within a single plpgsql function
execution. However, the memory context creation cost is amortized across
repeated executions of a statement, whereas of course PG_TRY won't be.
We can roughly estimate that PG_TRY would lose any time we loop through
the statement in question more than circa ten times. So I believe the
way I want to do it will win speed-wise in cases where it matters, but
it's not entirely an open-and-shut conclusion.
Anyway, there are enough other reasons not to go the PG_TRY route.
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
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, robertmhaas@gmail.com, alvherre@2ndquadrant.com, amit.kapila16@gmail.com
Subject: Re: Curing plpgsql's memory leaks for statement-lifespan values
In-Reply-To: <6969.1469630991@sss.pgh.pa.us>
References: <20160725211919.GA298355@alvherre.pgsql> <619.1469484240@sss.pgh.pa.us> <CA+TgmoYdovO69cEtd0UnYs57juSDN4gFX_+fe73P9TihS3gf2w@mail.gmail.com> <6969.1469630991@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