Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bQbok-0004Md-OG for pgsql-hackers@arkaria.postgresql.org; Fri, 22 Jul 2016 14:52:46 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1bQboj-0003RA-LM for pgsql-hackers@arkaria.postgresql.org; Fri, 22 Jul 2016 14:52:45 +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 1bQboj-0003R3-2M for pgsql-hackers@postgresql.org; Fri, 22 Jul 2016 14:52:45 +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 1bQbob-0004yD-JS for pgsql-hackers@postgresql.org; Fri, 22 Jul 2016 14:52:44 +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 u6MEqZ95022249; Fri, 22 Jul 2016 10:52:35 -0400 From: Tom Lane To: Craig Ringer cc: PostgreSQL Hackers Subject: Re: Curing plpgsql's memory leaks for statement-lifespan values In-reply-to: References: <17863.1469142152@sss.pgh.pa.us> Comments: In-reply-to Craig Ringer message dated "Fri, 22 Jul 2016 13:24:51 +0800" Date: Fri, 22 Jul 2016 10:52:35 -0400 Message-ID: <22248.1469199155@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 Craig Ringer writes: > On 22 July 2016 at 13:24, Craig Ringer 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