Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kaKP4-0005m2-Po for pgsql-bugs@arkaria.postgresql.org; Wed, 04 Nov 2020 15:08:50 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kaKP3-0007Gi-DK for pgsql-bugs@arkaria.postgresql.org; Wed, 04 Nov 2020 15:08:49 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kaKP3-0007GT-7N for pgsql-bugs@lists.postgresql.org; Wed, 04 Nov 2020 15:08:49 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kaKOz-0000Fm-P6 for pgsql-bugs@lists.postgresql.org; Wed, 04 Nov 2020 15:08:48 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 0A4F8i3X1134453; Wed, 4 Nov 2020 10:08:44 -0500 From: Tom Lane To: daniel@manitou-mail.org cc: pgsql-bugs@lists.postgresql.org Subject: Re: BUG #16700: Child table dependency loss after moving out of and back into the inheritance tree In-reply-to: <16700-39027e4b536105de@postgresql.org> References: <16700-39027e4b536105de@postgresql.org> Comments: In-reply-to PG Bug reporting form message dated "Wed, 04 Nov 2020 11:09:56 +0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1134451.1604502524.1@sss.pgh.pa.us> Date: Wed, 04 Nov 2020 10:08:44 -0500 Message-ID: <1134452.1604502524@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk PG Bug reporting form writes: > When dropping a column in a parent table, the change is propagated to child > tables. > But when a child has been moved out of the hierarchy and then back into > it, > this propagation appears to no longer work for that child table. I believe this is operating as designed. When you dis-inherit the child table, all its columns go to attinhcount = 0 and therefore get attislocal set to true (since the alternative would be to drop them). Re-inheriting increments attinhcount, but attislocal remains true. Then the DROP COLUMN on the parent reduces attinhcount back to zero, but since attislocal is still true, the column is not dropped. One could argue that the re-inherit step ought to clear attislocal. But I think that would just move the weird behaviors somewhere else, primarily because there's no principled reason for ALTER ... INHERIT to assume that the column never had a local definition. In any case, this mechanism was intentionally designed to err on the side of not throwing away data in questionable cases, and I think that's a smart bias to have. I believe there was a pretty thorough discussion of all this back when we invented the attinhcount/attislocal tracking mechanism (before that, there were some very unpleasant corner cases). You could try digging in the archives if you want more detail. regards, tom lane