Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1h47Tt-0001PI-1V for pgsql-hackers@arkaria.postgresql.org; Wed, 13 Mar 2019 17:15:53 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1h47Tr-0006MX-Jh for pgsql-hackers@arkaria.postgresql.org; Wed, 13 Mar 2019 17:15:51 +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_SHA1:256) (Exim 4.89) (envelope-from ) id 1h47Tr-0006KD-BY for pgsql-hackers@lists.postgresql.org; Wed, 13 Mar 2019 17:15:51 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1h47Tp-0005JZ-BV for pgsql-hackers@lists.postgresql.org; Wed, 13 Mar 2019 17:15:50 +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 x2DHFj8o007449; Wed, 13 Mar 2019 13:15:45 -0400 From: Tom Lane To: Robert Haas cc: Alvaro Herrera , PostgreSQL Hackers Subject: Re: hyrax vs. RelationBuildPartitionDesc In-reply-to: References: <20190313164232.GA5270@alvherre.pgsql> Comments: In-reply-to Robert Haas message dated "Wed, 13 Mar 2019 12:51:05 -0400" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <7447.1552497345.1@sss.pgh.pa.us> Date: Wed, 13 Mar 2019 13:15:45 -0400 Message-ID: <7448.1552497345@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Robert Haas writes: > On Wed, Mar 13, 2019 at 12:42 PM Alvaro Herrera > wrote: >> I remember going over this code's memory allocation strategy a bit to >> avoid the copy while not incurring potential leaks CacheMemoryContext; >> as I recall, my idea was to use two contexts, one of which is temporary >> and used for any potentially leaky callees, and destroyed at the end of >> the function, and the other contains the good stuff and is reparented to >> CacheMemoryContext at the end. So if you have any accidental leaks, >> they don't affect a long-lived context. You have to be mindful of not >> calling leaky code when you're using the permanent one. > Well, that assumes that the functions which allocate the good stuff do > not also leak, which seems a bit fragile. I'm a bit confused as to why there's an issue here at all. The usual plan for computed-on-demand relcache sub-structures is that we compute a working copy that we're going to return to the caller using the caller's context (which is presumably statement-duration at most) and then do the equivalent of copyObject to stash a long-lived copy into the relcache context. Is this case being done differently, and if so why? If it's being done the same, where are we leaking? I recall having noticed someplace where I thought the relcache partition support was simply failing to make provisions for cleaning up a cached structure at relcache entry drop, but I didn't have time to pursue it right then. Let me see if I can reconstruct what I was worried about. regards, tom lane