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 1tDKjz-00HZA0-G1 for pgsql-hackers@arkaria.postgresql.org; Tue, 19 Nov 2024 09:41:47 +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 1tDKjx-00C2CY-39 for pgsql-hackers@arkaria.postgresql.org; Tue, 19 Nov 2024 09:41:45 +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 1tDKjw-00C2CP-Mn for pgsql-hackers@lists.postgresql.org; Tue, 19 Nov 2024 09:41:45 +0000 Received: from fout-b3-smtp.messagingengine.com ([202.12.124.146]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tDKjv-002iri-8h for pgsql-hackers@lists.postgresql.org; Tue, 19 Nov 2024 09:41:44 +0000 Received: from phl-compute-05.internal (phl-compute-05.phl.internal [10.202.2.45]) by mailfout.stl.internal (Postfix) with ESMTP id EFCF7114013F; Tue, 19 Nov 2024 04:41:40 -0500 (EST) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-05.internal (MEProxy); Tue, 19 Nov 2024 04:41:41 -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=1732009300; x=1732095700; bh=R CVky1AxsppFDPFgjh8Z+ljKn932nHP0sk6/XPhcqoc=; b=Awv/PO+xDCh43Rmai SiRYfoU8QeKwavAbqiUEcO8W8iu1RYNnCIt7A+4K2aj5FRtot3oKxIIhDQ95HJII mBuiiGTZDHOgTKxJwhxy+e3HTH8dJ23tADr4L27PyPeoLjiCfSTdL6uPoSl2po/g E2cvVAWHcWLV6LJmCS43SNpb5ZiResmXlPgHJZc/FzsTtpRaxLfLeuvt5G4LI+2V lZqVvea/Su1nMx82Vaw7EOlzWD98J91YwggVVxEg9K1K8L1ILx5fiTaOOt81SdHW KD3chVYkJmVnbagM7gADyG2r/kyE8+j0e+EFSUk4moeXJtru/61yMe/paZUPN4Ei hkMdA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefuddrfedvgddtiecutefuodetggdotefrodftvf 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, 19 Nov 2024 04:41:40 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alvh.no-ip.org; s=schmee; t=1732009298; bh=SsuzANZuC7NOklk4njE2IANvsXhyK7hkeoIClznuqfw=; h=Date:From:To:Cc:Subject:In-Reply-To:From; b=QrZQFzm52hcuqlQmWL1dkmG4b7lSutMci6IqnNvxcpUXb7WMe6KqWme7XpoXsKTvd z2Ev4sNhDA44xFYb+ORgsVci/RwFJKLHf1zpG8sPVX5Mfc+WXRJwdq1A3BrmosViUv CbShnNZJ9YQnJied+H09J/HUdWThzlKCHwI9jmE4lOe7wbDLc01Dla5CaDcHAQJnNG 0hPu+W9SyI8ba1fSRwQ71pSnKEZe79rorrh2uZqJNtprvuWjHR7ldCvlTqWBOHIRxj 0npn/d9GRAeZ0Xxlmt9pUC24ebZpH8v5vivf/mKKFbsnsVvw3cBzAryq6j1Rlzb2N/ s1vOyAl6uxXmQ== Received: by schmee.alvh.no-ip.org (Postfix, from userid 1000) id A1A0C8C; Tue, 19 Nov 2024 10:41:38 +0100 (CET) Date: Tue, 19 Nov 2024 10:41:38 +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: <202411190941.bqiakaqi7tdz@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-14, Amit Langote wrote: > Sorry, here's the full example. Note I'd changed both > AddRelationNotNullConstraints() and AdjustNotNullInheritance() to not > throw an error *if* the table is a leaf partition when the NO INHERIT > of an existing constraint doesn't match that of the new constraint. > > create table p (a int not null) partition by list (a); > create table p1 partition of p for values in (1); > alter table p1 add constraint a_nn_ni not null a no inherit; Yeah, I think this behavior is bogus, because the user wants to have something (a constraint that will not inherit) but they cannot have it, because there is already a constraint that will inherit. The current behavior of throwing an error seems correct to me. With your patch, what this does is mark the constraint as "local" in addition to inherited, but that'd be wrong, because the constraint the user wanted is not of the same state. > On Wed, Nov 13, 2024 at 10:49 PM Alvaro Herrera wrote: > > 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 > > Hmm, we'll be doing something else for CHECK constraints if we apply my patch: > > create table p (a int not null, constraint check_a check (a > 0)) partition by list (a); > create table p1 partition of p (constraint check_a check (a > 0) no inherit) for values in (1); > NOTICE: merging constraint "check_a" with inherited definition > > \d p1 > Table "public.p1" > Column | Type | Collation | Nullable | Default > --------+---------+-----------+----------+--------- > a | integer | | not null | > Partition of: p FOR VALUES IN (1) > Check constraints: > "check_a" CHECK (a > 0) NO INHERIT > > I thought we were fine with allowing merging of such child > constraints, because leaf partitions can't have children to pass them > onto, so the NO INHERIT clause is essentially pointless. I'm beginning to have second thoughts about this whole thing TBH, as it feels inconsistent -- and unnecessary, if we get the patch to flip the INHERIT/NO INHERIT flag of constraints. > > - if the one being added is not NO INHERIT, then both constraints > > would have the same state and so we silently do nothing. > > Maybe we should emit some kind of NOTICE message in such cases? Hmm, I'm not sure. It's not terribly useful, is it? I mean, if the user wants to have a constraint, then whether the constraint is there or not, the end result is the same and we needn't say anything about it. It's only if the constraint is not what they want (because of mismatching INHERIT flag) that we throw some message. (I wonder if we'd throw an error if the proposed constraint has a different _name_ from the existing constraint. If a DDL script is expecting that the constraint will be named a certain way, then by failing to throw an error we might be giving confusing expectations.) > > * 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. > > So IIUC, there cannot be multiple *named* NOT NULL constraints for the > same column? That's correct. What I mean is that if you have a constraint, and you try to add another, then the reaction is to compare the desired constraint with the existing one; if the comparison yields okay, then we silently do nothing; if the comparison says both things are incompatible, we throw an error. In no case would we add a second constraint. > > 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. > > No worries. I want to ensure that the behaviors for NOT NULL and > CHECK constraints are as consistent as possible. Sounds good. > Anyway, for now, I've fixed my patch to only consider CHECK > constraints -- leaf partitions can have inherited CHECK constraints > that are marked NO INHERIT. 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. -- Álvaro Herrera Breisgau, Deutschland — https://www.EnterpriseDB.com/