Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VdH9L-0001Pf-Do for pgsql-hackers@arkaria.postgresql.org; Mon, 04 Nov 2013 10:12:47 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1VdH9K-00060J-QL for pgsql-hackers@arkaria.postgresql.org; Mon, 04 Nov 2013 10:12:46 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VdH9J-00060A-OU for pgsql-hackers@postgresql.org; Mon, 04 Nov 2013 10:12:45 +0000 Received: from moutng.kundenserver.de ([212.227.126.187]) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VdH9C-0002oP-5J for pgsql-hackers@postgresql.org; Mon, 04 Nov 2013 10:12:45 +0000 Received: from anarazel.de (p5DDC6D42.dip0.t-ipconnect.de [93.220.109.66]) by mrelayeu.kundenserver.de (node=mreu2) with ESMTP (Nemesis) id 0M8M5O-1VpyVg0v7y-00w25n; Mon, 04 Nov 2013 11:12:22 +0100 Received: by anarazel.de (Postfix, from userid 1000) id 9156A100AA1; Mon, 4 Nov 2013 11:12:21 +0100 (CET) Date: Mon, 4 Nov 2013 11:12:21 +0100 From: Andres Freund To: Tom Lane Cc: Jim Nasby , g.vanluffelen@qipc.com, pgsql-hackers@postgresql.org Subject: Re: [BUGS] BUG #8573: int4range memory consumption Message-ID: <20131104101221.GJ3567@awork2.anarazel.de> References: <18832.1383332908@sss.pgh.pa.us> <12646.1383420576@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <12646.1383420576@sss.pgh.pa.us> X-Provags-ID: V02:K0:qD3wj1tdJTTB+r0k5zKp3DGe4wufpIErlADI43Y9kHz 8DsqHwlWwWbH8e6WNPjRxWA2yWFszYj+5VP6yntJ6NY9PFl1iY hMQeBOB5xyDlXg+hUSkGr1jvysREsLLTmL6pKvlLzwD6h3R9aQ mC0Ay0QzbFrD1so5TtTw7SxtxUFA+xCb/VExyRptwxZA2IVG1w fsa+oq6F8CEjee54LVsKH+KovBEwfWSZNEzPDZt4tk6J/+/sYw X2ln0vhu4/+uIAtsxj1Jqm3xslqElo3cyVe7yGPaMz2qk/mUiS i32MjxCje02rFcTN+klMr+bGOYTQg4DDtIMnLdU5jeovLM9nzZ n21lTWRhAgHJoncWnak1B4ZEgQZPDtlr0ad8T7NfZ X-Pg-Spam-Score: -1.9 (-) 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 On 2013-11-02 15:29:36 -0400, Tom Lane wrote: > Attached is a proposed patch for this. It fixes most of the functions > in printtup.c to use a per-row memory context. (I did not bother to > fix debugtup(), which is used only in standalone mode. If you're doing > queries large enough for mem leaks to be problematic in standalone mode, > you're nuts.) FWIW, by that definition I have been nuts several time in the past - without much choice since I was recovering data from a corrupted cluster and the database couldn't be started normally. This now has gotten worse (even in the backbranches) since debugtup won't clean up detoasted data anymore. But I guess the solution for that is to use COPY in those situations which shouldn't have that problem and should work. Also, easier to parse ;) > My original thought had been to get rid of all pfree's of output function > results, so as to make the world safe for returning constant strings when > such functions find it appropriate. However, I ran into a showstopper > problem: SPI_getvalue(), which is little more than a wrapper around the > appropriate type output function, is documented as returning a pfree'able > string. Some though not all of the callers in core and contrib take the > hint and pfree the result, and I'm sure there are more in third-party > extensions. So if we want to allow output functions to return > non-palloc'd strings, it seems we have to either change SPI_getvalue()'s > API contract or insert a pstrdup() call in it. Neither of these is > attractive, mainly because the vast majority of output function results > would still be palloc'd even if we made aggressive use of the option not > to. That means that if we did the former, light testing wouldn't > necessarily show a problem if someone forgot to remove a pfree() after a > SPI_getvalue() call, and it also means that if we did the latter, the > pstrdup() would usually be a waste of cycles and space. I guess one option for the future is to to pstrdup() in SPI_getvalue() and adding a new function that tells whether the result can be freed or not. Then callers that care can move over. Although I'd guess that many of those caring will already use SPI_getbinval() manually. Greetings, Andres Freund -- Andres Freund http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Training & Services -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers