Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tFxsg-0006Mv-By for pgsql-hackers@arkaria.postgresql.org; Tue, 26 Nov 2024 15:53:38 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1tFxse-007dOK-Bt for pgsql-hackers@arkaria.postgresql.org; Tue, 26 Nov 2024 15:53:36 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tFxsd-007dOC-Va for pgsql-hackers@lists.postgresql.org; Tue, 26 Nov 2024 15:53:36 +0000 Received: from fhigh-a4-smtp.messagingengine.com ([103.168.172.155]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tFxsa-0049mS-Ux for pgsql-hackers@lists.postgresql.org; Tue, 26 Nov 2024 15:53:35 +0000 Received: from phl-compute-01.internal (phl-compute-01.phl.internal [10.202.2.41]) by mailfhigh.phl.internal (Postfix) with ESMTP id 37AFD1140117; Tue, 26 Nov 2024 10:53:30 -0500 (EST) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-01.internal (MEProxy); Tue, 26 Nov 2024 10:53:30 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :reply-to:subject:subject:to:to:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm1; t=1732636410; x=1732722810; bh=K ncakoRRyya0P03laM85C5sDh1VDUAz1+u3o7zUz9mU=; b=y8u8YTIQ+nhjlYRGO nCC4bvgcGcOUq9TipqTd6jacNY8S9oBo7IX/m132+G37BbDwtwnHP6Jv5YFEUhti tOsFEzEbUvcq9RC03nRR3tMOvMU0hgU5GqzCkivj2RkgX1UnD3VJaRzwbQTJRdo4 A5rSziBorsUlCac2t05I1SbOhhpAgNfpEnGA6dVBkpcgoKoTK7h3W8Tr9QLb8voC LMJmdKKKAiwRHEYaZoZYGz8+NYy4wZUufPoqHIJe7H/b/3EqSQsq18zmHyRF6F2S oDYasbJhYixgqAqyP5wWQxZ/EFfZggsg9PkC90QUwctfsdkC9IRMOpSgUG7wesQn Ut4dw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefuddrgeejgdejkecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdpuffr tefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnth hsucdlqddutddtmdenucfjughrpeffhffvvefukfggtggugfgjsehtkeertddttdejnecu hfhrohhmpeetlhhvrghrohcujfgvrhhrvghrrgcuoegrlhhvhhgvrhhrvgesrghlvhhhrd hnohdqihhprdhorhhgqeenucggtffrrghtthgvrhhnpedvkedtffduffdtffffheffhfej jefhgfeiueeukeejkeffgfdufffhudffffeuveenucffohhmrghinhepvghnthgvrhhprh hishgvuggsrdgtohhmnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghi lhhfrhhomheprghlvhhhvghrrhgvsegrlhhvhhdrnhhoqdhiphdrohhrghdpnhgspghrtg hpthhtohepfedpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtoheprghmihhtlhgrnhhg ohhtvgdtleesghhmrghilhdrtghomhdprhgtphhtthhopehrohgsvghrthhmhhgrrghsse hgmhgrihhlrdgtohhmpdhrtghpthhtohepphhgshhqlhdqhhgrtghkvghrsheslhhishht shdrphhoshhtghhrvghsqhhlrdhorhhg X-ME-Proxy: Feedback-ID: ia2694551:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 26 Nov 2024 10:53:29 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alvh.no-ip.org; s=schmee; t=1732636406; bh=y6v8tiIfa7ebYuRUQu+r+ttzjBnEnWZYYvbZ08DhVqI=; h=Date:From:To:Cc:Subject:In-Reply-To:From; b=LufT9XXYldt3i5RADh/vsg1WNsJbkyeUFZmvOuZ42QyRtRorJ/ssfJmP2agsneaXK 3GcoZrlwW4Z0PKYJoHEGUWf2CJ7YqdCTIXLa1RU8P0x+0xOjOjlJHBg0SDQYuAaHsi 8QJCivptOJNP/6kOnrFwftrTqngGJ1rDglNYTrwdVVjNsKelmRDB1VDDWhOvqUg1py J/4Qkup/OxhzwVMLtYoivzpxZqiX2grf9By+jd8Z2UzeGproi0M298FiGGdUxolSLP p2Mky9VbabT+b1061JxLDkzPkZjfEV+pMF7b3nDW3gZjpJT784lJh/vzP66emLU+zR hlQ7P6YnvX7cA== Received: by schmee.alvh.no-ip.org (Postfix, from userid 1000) id 464E595; Tue, 26 Nov 2024 16:53:26 +0100 (CET) Date: Tue, 26 Nov 2024 16:53:26 +0100 From: Alvaro Herrera To: Amit Langote Cc: Pg Hackers , Robert Haas Subject: Re: doc fail about ALTER TABLE ATTACH re. NO INHERIT Message-ID: <202411261553.ryi5cx2grom4@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 2024-Nov-20, Amit Langote wrote: > On Tue, Nov 19, 2024 at 6:41 PM Alvaro Herrera wrote: > Here's an example that I think matches the above description, which, > ISTM, leads to a state similar to what one would encounter with my > patch as described earlier: > > create table parent (a int not null); > create table child (a int, constraint a_not_null_child not null a) > inherits (parent); > NOTICE: merging column "a" with inherited definition > > \d+ child > Table "public.child" > Column | Type | Collation | Nullable | Default | Storage | > Compression | Stats target | Description > --------+---------+-----------+----------+---------+---------+-------------+--------------+------------- > a | integer | | not null | | plain | > | | > Not-null constraints: > "a_not_null_child" NOT NULL "a" (local, inherited) > Inherits: parent > Access method: heap > > I think the inherited constraint should be named parent_a_not_null, > but the constraint that gets stored is the user-specified constraint > in `create table child`. Yeah, the user-specified name taking precedence over using a name from inheritance was an explicit decision. I think this is working as intended. An important point is that pg_dump should preserve any constraint name; that's for example why we disallow ALTER TABLE DROP CONSTRAINT of an inherited constraint: previously I made that command reset the 'islocal' flag of the constraint and otherwise do nothing; but the problem is that if we allow that, then the constraint gets the wrong name after dump/restore. > Not sure, but perhaps the following piece of code of > AddRelationNotNullConstraints() should also check that the names > match? > > /* > * Search in the list of inherited constraints for any entries on the > * same column; determine an inheritance count from that. Also, if at > * least one parent has a constraint for this column, then we must not > * accept a user specification for a NO INHERIT one. Any constraint > * from parents that we process here is deleted from the list: we no > * longer need to process it in the loop below. > */ I was of two minds about checking that the constraint names match, but in the end I decided it wasn't useful and limiting, because you cannot have a particular name in the children if you want to. One thing that distinguishes not-null constraints from check ones is that when walking down inheritance trees we match by the column that the apply to, rather than by name as check constraints do. So the fact that the names don't match doesn't harm. That would not fly for check constraints. > Unless the inherited NOT NULL constraints are not required to have the > same name. Yep. > > I agree that both types of constraints should behave as similarly as > > possible in as many ways as possible. Behavioral differences are > > unlikely to be cherished by users. > > To be clear, I suppose we agree on continuing to throw an error when > trying to define a NO INHERIT CHECK constraint on a leaf partition. > That is to match the behavior we currently (as of 14e87ffa5) have for > NOT NULL constraints. Yeah. I think we should only worry to the extent that these things trouble users over what they can and cannot do with tables. Adding a NO INHERIT constraint to a partition, just so that they can continue to have the constraint after they detach and that the constraint doesn't affect any tables that are added as children ... doesn't seem a very important use case. _But_, for anybody out there that does care about such a thing, we might have an ALTER TABLE command to change a constraint from NO INHERIT to INHERIT, and perhaps vice-versa. -- Álvaro Herrera Breisgau, Deutschland — https://www.EnterpriseDB.com/ "No es bueno caminar con un hombre muerto"