Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ogrY2-0001T1-Dd for pgsql-hackers@arkaria.postgresql.org; Fri, 07 Oct 2022 17:54:10 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1ogrY0-0002gz-Rf for pgsql-hackers@arkaria.postgresql.org; Fri, 07 Oct 2022 17:54:08 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ogrY0-0002a8-12 for pgsql-hackers@lists.postgresql.org; Fri, 07 Oct 2022 17:54:08 +0000 Received: from wout3-smtp.messagingengine.com ([64.147.123.19]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ogrXv-0001mR-Ni for pgsql-hackers@postgresql.org; Fri, 07 Oct 2022 17:54:07 +0000 Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.west.internal (Postfix) with ESMTP id 1D71F32008FB; Fri, 7 Oct 2022 13:53:59 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute1.internal (MEProxy); Fri, 07 Oct 2022 13:53:59 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:reply-to:sender :subject:subject:to:to:x-me-proxy:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm3; t=1665165238; x=1665251638; bh=J AmmEG+zPGrxDqQf/KvNBTuBixRvIe/G/dW8wbCmHcg=; b=k+vRXyNL6/mVgnfW0 Jr0JLK5FXC4kQvLZaC5lfZK5gTaD6hdu8kL0MhCkdcz+39qLSuWCrHWqtD8VB24T FwzrUjZVslUYsWOAS10FpkfxXGwqLADo4hxA4yKW4PHvku4SH/gOQJbPRkln2CfA s+ion2QRsaKb2MI8gVhYf6Lm/bjY61sElWtbaGB8UTYm1M/dzHqWAdbHESRxJ1ae wb/KhPar5Ux53sempCvVFNWQzzV4ynVctZTgExj6oWN7LgA05OfP6VYmIvKPpMFl uXeYAqVLPBy2yTW7qt4hqpiPMr9Kpc4EtIGVwiksQd39LlK7TzD93vnMpu6Mgod3 4F3wg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvfedrfeeijedguddukecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpeffhffvvefukfggtggugfgjsehtkeertddttdejnecuhfhrohhmpeetlhhv rghrohcujfgvrhhrvghrrgcuoegrlhhvhhgvrhhrvgesrghlvhhhrdhnohdqihhprdhorh hgqeenucggtffrrghtthgvrhhnpedvkedtffduffdtffffheffhfejjefhgfeiueeukeej keffgfdufffhudffffeuveenucffohhmrghinhepvghnthgvrhhprhhishgvuggsrdgtoh hmnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheprghl vhhhvghrrhgvsegrlhhvhhdrnhhoqdhiphdrohhrgh X-ME-Proxy: Feedback-ID: ia2694551:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 7 Oct 2022 13:53:57 -0400 (EDT) Received: by perhan.alvh.no-ip.org (Postfix, from userid 1000) id 2887662; Fri, 7 Oct 2022 19:53:55 +0200 (CEST) Date: Fri, 7 Oct 2022 19:53:55 +0200 From: Alvaro Herrera To: Jehan-Guillaume de Rorthais Cc: Zhihong Yu , pgsql-hackers Subject: Re: [BUG] parenting a PK constraint to a self-FK one (Was: Self FK oddity when attaching a partition) Message-ID: <20221007175355.2ldgha4mmzewvauu@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20221005164048.exmpnpqzfkrgmqtx@alvherre.pgsql> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 2022-Oct-05, Alvaro Herrera wrote: > Backpatching this to 12 shows yet another problem -- the topmost > relation acquires additional FK constraints, not yet sure why. I think > we must have fixed something in 13 that wasn't backpatched, but I can't > remember what it is and whether it was intentionally not backpatched. This was actually a mismerge. Once I fixed that, it worked properly. However, there was another bug, which only showed up when I did a DETACH, ATTACH, and repeat. The problem is that when we detach, the no-longer-partition retains an FK constraint to the partitioned table. This is good -- we want that one -- but when we reattach, then we see that the partitioned table is being referenced from outside, so we consider that another constraint that we need to add the partition to, *in addition to the constraint that we need to clone*. So we need to ignore both a self-referencing FK that goes to the partitioned table, as well as a self-referencing one that comes from the partition-to-be. When we do that, then the clone correctly uses that one as the constraint to retain and attach into the hierarchy of constraints, and everything [appears to] work correctly. So I've pushed this, and things are now mostly good. Two problems remain, though I don't think either of them is terribly serious: 1. one of the constraints in the final hierarchy is marked as not validated. I mentioned this before. 2. (only in 15) There are useless pg_depend rows for the pg_trigger rows, which make them depend on their parent pg_trigger rows. This is not related to self-referencing foreign keys, but I just happened to notice because I was examining the catalog contents with the added test case. I think this breakage is due to f4566345cf40. I couldn't find any actual misbehavior caused by these extra pg_depend entries, but we should not be creating them anyway. -- Álvaro Herrera Breisgau, Deutschland — https://www.EnterpriseDB.com/ "Por suerte hoy explotó el califont porque si no me habría muerto de aburrido" (Papelucho)