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 1ijP1T-0000ba-0B for pgsql-hackers@arkaria.postgresql.org; Mon, 23 Dec 2019 14:49:27 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1ijP1R-0000NU-OV for pgsql-hackers@arkaria.postgresql.org; Mon, 23 Dec 2019 14:49:25 +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 1ijP1R-0000Iu-Eu for pgsql-hackers@lists.postgresql.org; Mon, 23 Dec 2019 14:49:25 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ijP1N-0000JN-UB for pgsql-hackers@lists.postgresql.org; Mon, 23 Dec 2019 14:49:25 +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 xBNEnHwe025384; Mon, 23 Dec 2019 09:49:17 -0500 From: Tom Lane To: Amit Langote cc: PostgreSQL Hackers Subject: Re: unsupportable composite type partition keys In-reply-to: References: <5361.1576602769@sss.pgh.pa.us> <28160.1576676326@sss.pgh.pa.us> <26766.1576947735@sss.pgh.pa.us> <24653.1576962784@sss.pgh.pa.us> Comments: In-reply-to Amit Langote message dated "Mon, 23 Dec 2019 18:42:36 +0900" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <25382.1577112556.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Mon, 23 Dec 2019 09:49:16 -0500 Message-ID: <25383.1577112556@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Amit Langote writes: > On Sun, Dec 22, 2019 at 6:13 AM Tom Lane wrote: > + * To ensure that it's not leaked completely, re-attach it = to the > + * new reldesc, or make it a child of the new reldesc's rd_= pdcxt > + * in the unlikely event that there is one already. (See h= ack in > + * RelationBuildPartitionDesc.) > While I can imagine that RelationBuildPartitionDesc() might encounter > an old partition descriptor making the re-parenting hack necessary > there, I don't see why it's needed here, because a freshly built > relation descriptor would not contain the partition descriptor after > this patch. Well, as the comment says, that's probably unreachable today. But I could see it happening in the future, particularly if we ever allow partitioned system catalogs. There are a lot of paths through this code that are not obvious to the naked eye, and some of them can cause relcache entries to get populated behind-your-back. Most of relcache.c is careful about this; I do not see an excuse for the partition-data code to be less so, even if we think it can't happen today. (I notice that RelationBuildPartitionKey is making a similar assumption that the partkey couldn't magically appear while it's working, and I don't like it much there either.) >> * It'd be better to declare RelationGetPartitionKey and >> RelationGetPartitionDesc in relcache.h and get their callers out of the >> business of including rel.h, where possible. > Although I agree to declare them in relcache.h, that doesn't reduce > the need to include rel.h in their callers much, because anyplace that > uses RelationGetPartitionDesc() is also very likely to use > RelationGetRelid() which is in rel.h. Hm. Well, we can try anyway. > [1] https://www.postgresql.org/message-id/CA%2BHiwqFucUh7hYkfZ6x1MVcs_R2= 4eUfNVuRwdE_FwuwK8XpSZg%40mail.gmail.com Oh, interesting --- I hadn't been paying much attention to that thread. I'll compare your PoC there to what I did. regards, tom lane