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 1h48jj-0006FP-Kw for pgsql-hackers@arkaria.postgresql.org; Wed, 13 Mar 2019 18:36:19 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1h48ji-0001YB-Bd for pgsql-hackers@arkaria.postgresql.org; Wed, 13 Mar 2019 18:36:18 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1h48ji-0001Y4-0V for pgsql-hackers@lists.postgresql.org; Wed, 13 Mar 2019 18:36:18 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1h48jf-000823-Ki for pgsql-hackers@lists.postgresql.org; Wed, 13 Mar 2019 18:36:16 +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 x2DIaDoB011077; Wed, 13 Mar 2019 14:36:13 -0400 From: Tom Lane To: Alvaro Herrera cc: Robert Haas , PostgreSQL Hackers Subject: Re: hyrax vs. RelationBuildPartitionDesc In-reply-to: <20190313182145.GA488@alvherre.pgsql> References: <20190313182145.GA488@alvherre.pgsql> Comments: In-reply-to Alvaro Herrera message dated "Wed, 13 Mar 2019 15:21:45 -0300" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <11075.1552502173.1@sss.pgh.pa.us> Date: Wed, 13 Mar 2019 14:36:13 -0400 Message-ID: <11076.1552502173@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Alvaro Herrera writes: > You do? Unless I misunderstood, your options are: > 1. (the patch you attached) create a temporary memory context that is > used for everything, then at the end copy the good stuff to CacheMemCxt > (or a sub-context thereof). This still needs to copy. > 2. create a temp memory context, do everything there, do retail freeing > of everything we don't want, reparenting the context to CacheMemCxt. > Hope we didn't forget to pfree anything. > How is any of those superior to what I propose? I doubt that what you're suggesting is terribly workable. It's not just RelationBuildPartitionDesc that's at issue. Part of what will be the long-lived data structure is made by partition_bounds_create, and that invokes quite a boatload of code that both makes the final data structure and leaks a lot of intermediate junk. Having to be very careful about permanent vs temporary data throughout all of that seems like a recipe for bugs. The existing code in RelationBuildPartitionDesc is already pretty good about avoiding copying of data other than the output of partition_bounds_create. In fact, I think it's already close to what you're suggesting other than that point. So I think --- particularly given that we need something we can back-patch into v11 --- that we shouldn't try to do anything much more complicated than what Robert is suggesting. regards, tom lane