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 1tTQ85-005UVd-DN for pgsql-hackers@arkaria.postgresql.org; Thu, 02 Jan 2025 18:41:09 +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 1tTQ84-000PjW-4x for pgsql-hackers@arkaria.postgresql.org; Thu, 02 Jan 2025 18:41:07 +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 1tTQ83-000Pi8-Ig for pgsql-hackers@lists.postgresql.org; Thu, 02 Jan 2025 18:41:07 +0000 Received: from fout-a7-smtp.messagingengine.com ([103.168.172.150]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tTQ7z-002rkU-No for pgsql-hackers@lists.postgresql.org; Thu, 02 Jan 2025 18:41:06 +0000 Received: from phl-compute-05.internal (phl-compute-05.phl.internal [10.202.2.45]) by mailfout.phl.internal (Postfix) with ESMTP id 602CB1380181; Thu, 2 Jan 2025 13:41:02 -0500 (EST) Received: from phl-imap-07 ([10.202.2.97]) by phl-compute-05.internal (MEProxy); Thu, 02 Jan 2025 13:41:02 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t= 1735843262; x=1735929662; bh=7hMMMnk3dVCbAwZX9X+iQ3A8hRmIiyQEpYQ ZbWLzvX4=; b=CzPGgOxKAdymsNaRwktu6oEKwEL7ZlItKngpcLCg55Npntxv0MZ AtbdOROg4rNUO8etU6FeZdrmUrn/B0h6oJ9F3D09qtWyso5453nlSOp3ix0JxMKY UZTsXsjk+KRjgMoV/6DDYYg6iTLpaVnfJqe3sn4OWN0/8u2ylbAmdU6f3ews1aOW +VJgxs5GGwRQTeL+XEB63VeKo0VWl5pGoE/2ItfHEBSc2bH6DvosfSjSLVB7/VuX NdGblDo/nEkmKU6a+0ayf4EIC/wy8CBGm0wXgqB8G3ZvsJk3ZjLdFLvmlppO1ruJ zfVLYJZrVVHzQXDVbDmicjLMIlh2zFEi0uQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefuddrudefvddgudduiecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdp uffrtefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivg hnthhsucdlqddutddtmdenucfjughrpefoggffhffvkfgjfhfutgesrgdtreerredtjeen ucfhrhhomheplmhlvhgrrhhoucfjvghrrhgvrhgruceorghlvhhhvghrrhgvsegrlhhvhh drnhhoqdhiphdrohhrgheqnecuggftrfgrthhtvghrnhepfefghfehleduiefgfeetleev jedtkeekkeefleeuffffveelkeehudffteetffffnecuvehluhhsthgvrhfuihiivgeptd enucfrrghrrghmpehmrghilhhfrhhomheprghlvhhhvghrrhgvsegrlhhvhhdrnhhoqdhi phdrohhrghdpnhgspghrtghpthhtohepvddpmhhouggvpehsmhhtphhouhhtpdhrtghpth htohepshhulhgrmhhulhesghhmrghilhdrtghomhdprhgtphhtthhopehpghhsqhhlqdhh rggtkhgvrhhssehlihhsthhsrdhpohhsthhgrhgvshhqlhdrohhrgh X-ME-Proxy: Feedback-ID: ia2694551:Fastmail Received: by mailuser.phl.internal (Postfix, from userid 501) id E140ABA0070; Thu, 2 Jan 2025 13:41:01 -0500 (EST) X-Mailer: MessagingEngine.com Webmail Interface MIME-Version: 1.0 Date: Thu, 02 Jan 2025 19:40:25 +0100 From: =?UTF-8?Q?=C3=81lvaro_Herrera?= To: "Amul Sul" , "pgsql-hackers@lists.postgresql.org" Message-Id: In-Reply-To: References: Subject: Re: Allow NOT VALID foreign key constraints on partitioned tables. Content-Type: multipart/alternative; boundary=f99149d167d64e39b0e57ad003c00e69 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --f99149d167d64e39b0e57ad003c00e69 Content-Type: text/plain Content-Transfer-Encoding: 7bit On Thu, Jan 2, 2025, at 5:49 PM, Amul Sul wrote: > When adding a new FK constraint or attaching a partitioned table, where > matching FK constraints are merged, we allow the parent constraint to be NOT > VALID while the child constraint remains VALID, which is harmless. However, the > reverse scenario -- where the parent constraint is VALID and the child is NOT > VALID -- is incorrect. To address this, when merging a NOT VALID FK constraint > from the child with a VALID parent constraint, it implicitly validates the > child constraint against its existing data and marks it as VALID. This behavior > aligns with adding a new FK constraint directly to the child table, which would > also validate the existing data. Hmm, I'm not sure about this, which may cause surprising delays. Maybe it would be better that the operation fails with an error, so that the user can do VALIDATE CONSTRAINT explicitly and retry the ATTACH once all the partitions have been so processed. --f99149d167d64e39b0e57ad003c00e69 Content-Type: text/html Content-Transfer-Encoding: quoted-printable

=
On Thu, Jan 2, 2025, at 5:49 PM, Amul Sul wrote:
When adding a new FK co= nstraint or attaching a partitioned table, where
matching = FK constraints are merged, we allow the parent constraint to be NOT
<= /div>
VALID while the child constraint remains VALID, which is harml= ess. However, the
reverse scenario -- where the parent con= straint is VALID and the child is NOT
VALID -- is incorrec= t. To address this, when merging a NOT VALID FK constraint
from the child with a VALID parent constraint, it implicitly validates = the
child constraint against its existing data and marks i= t as VALID. This behavior
aligns with adding a new FK cons= traint directly to the child table, which would
also valid= ate the existing data.

Hmm, I'= m not sure about this, which may cause surprising delays. Maybe it would= be better that the operation fails with an error, so that the user can = do VALIDATE CONSTRAINT explicitly and retry the ATTACH once all the part= itions have been so processed.
--f99149d167d64e39b0e57ad003c00e69--