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 1tiXqD-00HCFm-4K for pgsql-hackers@arkaria.postgresql.org; Thu, 13 Feb 2025 11:57:13 +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 1tiXqA-006OWC-3t for pgsql-hackers@arkaria.postgresql.org; Thu, 13 Feb 2025 11:57:10 +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 1tiXq9-006OW4-PB for pgsql-hackers@lists.postgresql.org; Thu, 13 Feb 2025 11:57:10 +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.96) (envelope-from ) id 1tiXq7-000bZP-2M for pgsql-hackers@postgresql.org; Thu, 13 Feb 2025 11:57:10 +0000 Received: from phl-compute-08.internal (phl-compute-08.phl.internal [10.202.2.48]) by mailfout.stl.internal (Postfix) with ESMTP id 71FA1114017B; Thu, 13 Feb 2025 06:57:05 -0500 (EST) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-08.internal (MEProxy); Thu, 13 Feb 2025 06:57:05 -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=1739447825; x=1739534225; bh=K kmtyK1r4MihwL8uENh11tBlB+JzepB1NcLqUdRZEYA=; b=cbjwP2WB0Gtn2lNhA huWnSrwUBfaU18nvo/a/ztJ8aamScSCNDYihQdctW4zoyDQ+x4CZfyP3vSkxU59Z pPq0G8N0QticJd+44yFHr6UqlEfNCIysG6El7ipDR0I7wu4tddejjs6gYzlKFRSi nK33v1I9KgpO580izYaVsExeIKPaH5of23F6ZKyH5vrfOxmvlTmOOjdg9tzSWiAb RserEd2r3xrJaCyHAgR/IQO0VLF+ZzFRCRHv/xLYjCyF9oiW4QLI+DCsIT2cUxlA WLwcHaMmCfAMMEV6e3H6bRPK6YaHlL2wuK8ad/O/GIoM7L9uDPMNDIDO5k3CqQdw jLe6w== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgdegieejudcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdp uffrtefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivg hnthhsucdlqddutddtmdenucfjughrpeffhffvvefukfggtggugfgjsehtkeertddttdej necuhfhrohhmpemllhhvrghrohcujfgvrhhrvghrrgcuoegrlhhvhhgvrhhrvgesrghlvh hhrdhnohdqihhprdhorhhgqeenucggtffrrghtthgvrhhnpedvheeuffehgfeukeeufeeh hefghfeugfefudekjeevudffgeffkeegffffveegheenucffohhmrghinhepvghnthgvrh hprhhishgvuggsrdgtohhmnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehm rghilhhfrhhomheprghlvhhhvghrrhgvsegrlhhvhhdrnhhoqdhiphdrohhrghdpnhgspg hrtghpthhtohepkedpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepjhhovghlsegt ohhmphhilhgvrhdrohhrghdprhgtphhtthhopehpvghtvghrsegvihhsvghnthhrrghuth drohhrghdprhgtphhtthhopehsuhhrrghjrdhkhhgrrhgrghgvsegvnhhtvghrphhrihhs vggusgdrtghomhdprhgtphhtthhopegrshhhuhhtohhshhdrsggrphgrthdrohhsshesgh hmrghilhdrtghomhdprhgtphhtthhopehishgrrggtrdhmohhrlhgrnhgusehgmhgrihhl rdgtohhmpdhrtghpthhtohepjhhirghnrdhunhhivhgvrhhsrghlihhthiesghhmrghilh drtghomhdprhgtphhtthhopehsuhhlrghmuhhlsehgmhgrihhlrdgtohhmpdhrtghpthht ohepphhgshhqlhdqhhgrtghkvghrshesphhoshhtghhrvghsqhhlrdhorhhg X-ME-Proxy: Feedback-ID: ia2694551:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 13 Feb 2025 06:57:04 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alvh.no-ip.org; s=schmee; t=1739447823; bh=zAAqaP9VOLO4UA7ap84/9rCZpcTRsxa1/kNOKPZLRGY=; h=Date:From:To:Cc:Subject:In-Reply-To:From; b=mci7VB0NcftiJarLAqeh+axSVPLsqxVv780+1uXlg1J/hCgKgPWue4IxbN/4GAlCp dZrNr2kyS28mXfXH2i0f3enQKcD05FTgrbFk+7XSe9vasvxLYHbbjFsMzm6jDN/OUL 5BEArE7zgS/vC1VDOxDA9z9EWrjx22mEs1X+9V2fYLQZxfhJW1gH3JFHADa0geduHp sacRZavQmkubvl9oEqbLxLf4mOSKHmjgSRiXWWEgQI5yH1KXd9Ts1etgYUMudoT81v PjmOK1lRTSlxHTuCvilDNlbbZBO8GWwSQhTxtcpGNUxiI4E67dG92QRY3Z86ndZgBN TKbH4/a7FRoJw== Received: by schmee.alvh.no-ip.org (Postfix, from userid 1000) id 416056D; Thu, 13 Feb 2025 12:57:03 +0100 (CET) Date: Thu, 13 Feb 2025 12:57:03 +0100 From: =?utf-8?Q?=C3=81lvaro?= Herrera To: Ashutosh Bapat Cc: Peter Eisentraut , Isaac Morland , Amul Sul , jian he , PostgreSQL-development , Joel Jacobson , Suraj Kharage Subject: Re: NOT ENFORCED constraint feature Message-ID: <202502131157.4oqj3eha7yum@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 2025-Feb-13, Ashutosh Bapat wrote: > > So considering that, I think a three-state system makes more sense. > > Something like: > > > > 1) NOT ENFORCED -- no data is checked > > 2) NOT VALID -- existing data is unchecked, new data is checked > > 3) ENFORCED -- all data is checked > > > > Transitions: > > > > (1) - [ ALTER TABLE ... ALTER CONSTRAINT ... NOT VALID ] -> (2) > > Per your notation, this means the the constraint is not enforced but > new data is checked - that seems a contradiction, how would we check > the data when the constraint is not being enforced. Or do you suggest > that we convert a NOT ENFORCED constraint to ENFORCED as a result of > converting it to NOT VALID? I agree this one is a little weird. For this I would have the command be ALTER TABLE ... ALTER CONSTRAINT ... ENFORCED NOT VALID this way it's explicit that what we want is flip the ENFORCED bit while leaving NOT VALID as-is. > > (2) - [ ALTER TABLE ... VALIDATE CONSTRAINT ... ] -> (3) > > As a result of this a not enforced constraint would turn into an > enforced constraint. The user might have intended to just validate the > data but not enforce it to avoid paying price for the checks on new > data. I'm not sure there's a use case for validating existing data without starting to enforce the constraint. The data can become invalid immediately after you've run the command, so why bother? > I think, what you intend to say is clearer with 4 state system {NE, E} > * {NV, V} = {(NE, NV), (NE, V), (E, NV), (E, V)} where (NE, V) is > unreachable. Let's name them S1, S2, S3, S4 respectively. [...] > Notice that there are no edges to and from S2. So why list it as a possible state? -- Álvaro Herrera 48°01'N 7°57'E — https://www.EnterpriseDB.com/ "Las mujeres son como hondas: mientras más resistencia tienen, más lejos puedes llegar con ellas" (Jonas Nightingale, Leap of Faith)