Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bSQ9t-00039R-1r for pgsql-hackers@arkaria.postgresql.org; Wed, 27 Jul 2016 14:50:05 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1bSQ9s-000719-5M for pgsql-hackers@arkaria.postgresql.org; Wed, 27 Jul 2016 14:50:04 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1bSQ9q-0006zb-BR for pgsql-hackers@postgresql.org; Wed, 27 Jul 2016 14:50:02 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1bSQ9j-0000dJ-HC for pgsql-hackers@postgresql.org; Wed, 27 Jul 2016 14:50:01 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id u6REnpZp006970; Wed, 27 Jul 2016 10:49:51 -0400 From: Tom Lane To: Robert Haas cc: Alvaro Herrera , Amit Kapila , pgsql-hackers Subject: Re: Curing plpgsql's memory leaks for statement-lifespan values In-reply-to: References: <20160725211919.GA298355@alvherre.pgsql> <619.1469484240@sss.pgh.pa.us> Comments: In-reply-to Robert Haas message dated "Mon, 25 Jul 2016 22:54:39 -0400" Date: Wed, 27 Jul 2016 10:49:51 -0400 Message-ID: <6969.1469630991@sss.pgh.pa.us> X-Pg-Spam-Score: -3.2 (---) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org Robert Haas writes: > On Mon, Jul 25, 2016 at 6:04 PM, Tom Lane 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