Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e8C8a-0007fN-2j for pgsql-hackers@arkaria.postgresql.org; Fri, 27 Oct 2017 21:25:56 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1e8C8Z-0003vK-9k for pgsql-hackers@arkaria.postgresql.org; Fri, 27 Oct 2017 21:25:55 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1e8C8X-0003pK-Ml for pgsql-hackers@postgresql.org; Fri, 27 Oct 2017 21:25:53 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1e8C8V-0000yC-54 for pgsql-hackers@postgresql.org; Fri, 27 Oct 2017 21:25:52 +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 v9RLPhfD012196; Fri, 27 Oct 2017 17:25:43 -0400 From: Tom Lane To: Robert Haas cc: Alvaro Herrera , Pg Hackers , Maksim Milyutin , Amit Langote Subject: Re: Proposal: Local indexes for partitioned table In-reply-to: References: <20171023151251.j75uoe27gajdjmlm@alvherre.pgsql> <20171027172730.eh2domlkpn4ja62m@alvherre.pgsql> Comments: In-reply-to Robert Haas message dated "Fri, 27 Oct 2017 22:18:06 +0200" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <12194.1509139543.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Fri, 27 Oct 2017 17:25:43 -0400 Message-ID: <12195.1509139543@sss.pgh.pa.us> 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 Fri, Oct 27, 2017 at 7:27 PM, Alvaro Herrera = wrote: >> I noticed that RelationBuildPartitionKey is generating a partition key >> in a temp context, then creating a private context and copying the key >> into that. That seems leftover from some previous iteration of some >> other patch; I think it's pretty reasonable to create the new context >> right from the start and allocate the key there directly instead. Then >> there's no need for copy_partition_key at all. > We could do that, but the motivation for the current system was to > avoid leaking memory in a long-lived context. I think the same > technique is used elsewhere for similar reasons. I admit I haven't > checked whether there would actually be a leak here if we did it as > you propose, but I wouldn't find it at all surprising. Another key point is to avoid leaving a corrupted relcache entry behind if you fail partway through. I think that the current coding is RelationBuildPartitionKey is safe, although it's far too undercommented for my taste. (The ordering of the last few steps is *critical*.) It might work to build the new key in a context that's initially a child of CurrentMemoryContext, then reparent it to be a child of CacheMemoryContext when done. But you'd have to look at whether that would end up wasting long-lived memory, if the build process generates any cruft in the same context. regards, tom lane --=20 Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers