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 1tBDkf-002Yhf-90 for pgsql-hackers@arkaria.postgresql.org; Wed, 13 Nov 2024 13:49:44 +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 1tBDka-00EfzR-NY for pgsql-hackers@arkaria.postgresql.org; Wed, 13 Nov 2024 13:49:41 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tBDka-00EfzE-B3 for pgsql-hackers@lists.postgresql.org; Wed, 13 Nov 2024 13:49:40 +0000 Received: from fout-a7-smtp.messagingengine.com ([103.168.172.150]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tBDkX-001flQ-NB for pgsql-hackers@lists.postgresql.org; Wed, 13 Nov 2024 13:49:39 +0000 Received: from phl-compute-11.internal (phl-compute-11.phl.internal [10.202.2.51]) by mailfout.phl.internal (Postfix) with ESMTP id 9F8781380652; Wed, 13 Nov 2024 08:49:36 -0500 (EST) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-11.internal (MEProxy); Wed, 13 Nov 2024 08:49:36 -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=fm3; t=1731505776; x=1731592176; bh=c 8QKn89PuAP35kdDYPot3SHuyUf+tklhoLg45TNUyww=; b=nab995zK7WiV7mbmy vaR460dHt9NAYNc/y7VmnFwAXnHVkcKfT2Chr/GxBolc/QOVH4EztXtd3Vx3BbOE 9TGmDmkevBPPOLTzOPFYP9UlrNUp8+TJaAkH45zRc/f1dYMKr6pjSAH/xcuegRC6 Fg/aa3OkZg4Ory/k376f/APsVjwIewW6VgoQ6Zh0gWqNLf/q2a8rcWZse1HhEWRR S/quTwiimMv8TMLYiK5lQOnUZKT0xEb/u7F9GFkMmNbJIAeaoFSFYRo+qmTymN5Q GSJdxLIIplCSmy8qtkuHH0Sbz03gm1OtIJtKjOBq0FXry10zC21nuVpNrctB33FO i/HyQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefuddrvddtgdehiecutefuodetggdotefrodftvf 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; Wed, 13 Nov 2024 08:49:36 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alvh.no-ip.org; s=schmee; t=1731505774; bh=LaeTsVpgMMdMdYvpgPlYdVdSS8pCRrzIor6vTkYZi9g=; h=Date:From:To:Cc:Subject:In-Reply-To:From; b=Ddb8Fw4jjbLLRb5w0ZDIUz6Ai7cqz+xS8zheeonMoc8QK/yj8vp6wZgwjYURiGcxW 2aPQUZQtdpL47wUEHFByOw/xSiZkLteIYrKlobiRUTjErHIyecly3u8j0Z5rV2OW32 Z1MM4u5H223syEYp1tAMIK5ETzD1Dj3I03FU/AdLoaVoUDxEaJctUWpNozJUSOooYW URKGFp0S6QNrLK3fFbHbb1BCwmn76npXVBk1OQDff4c95qeL2qEl98NRLbzxvKulYZ wCBCnO8PbEkxPnmysmiwH+9P03LtG/RgV/1lQjrYkfz8Zq42noZDVMur1h/BPrM0wb UzPlmyp+rTWNQ== Received: by schmee.alvh.no-ip.org (Postfix, from userid 1000) id 933D79B; Wed, 13 Nov 2024 14:49:34 +0100 (CET) Date: Wed, 13 Nov 2024 14:49:34 +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: <202411131349.fg47nc7ssdog@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-13, Amit Langote wrote: > I rebased my patch over 14e87ffa5c54 and noticed that NOT NULL > constraints can also (or not) be marked NO INHERIT. I think we should > allow NO INHERIT NOT NULL constraints on leaf partitions just like > CHECK constraints, so changed AddRelationNotNullConstraints() that way > and added some tests. OK, looks good. > However, I noticed that there is no clean way to do that for the following case: > > ALTER TABLE leaf_partition ADD CONSTRAINT col_nn_ni NOT NULL col NO INHERIT; Sorry, I didn't understand what's the initial state. Does the constraint already exist here or not? > If I change the new function AdjustNotNullInheritance() added by your > commit to not throw an error for leaf partitions, the above constraint > (col_nn_ni) is not stored at all, because the function returns true in > that case, which means the caller does nothing with the constraint. I > am not sure what the right thing to do would be. If we return false, > the caller will store the constraint the first time around, but > repeating the command will again do nothing, not even prevent the > addition of a duplicate constraint. Do you mean if we return false, it allows two not-null constraints for the same column? That would absolutely be a bug. I think: * if a leaf partition already has an inherited not-null constraint from its parent and we want to add another one, we should: - if the one being added is NO INHERIT, then throw an error, because we cannot merge them - if the one being added is not NO INHERIT, then both constraints would have the same state and so we silently do nothing. * if a leaf partition has a locally defined not-null marked NO INHERIT - if we add another NO INHERIT, silently do nothing - if we add an INHERIT one, throw an error because cannot merge. If you want, you could leave the not-null constraint case alone and I can have a look later. It wasn't my intention to burden you with that. -- Álvaro Herrera 48°01'N 7°57'E — https://www.EnterpriseDB.com/ It does it in a really, really complicated way why does it need to be complicated? Because it's MakeMaker.