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 1t3GHb-00BWkO-L1 for pgsql-hackers@arkaria.postgresql.org; Tue, 22 Oct 2024 14:54:51 +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 1t3GHa-000U9v-0f for pgsql-hackers@arkaria.postgresql.org; Tue, 22 Oct 2024 14:54:50 +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 1t3GHZ-000U9m-F8 for pgsql-hackers@lists.postgresql.org; Tue, 22 Oct 2024 14:54:50 +0000 Received: from mail1.dalibo.net ([51.159.93.128] helo=mail.dalibo.com) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1t3GHX-002PJb-Mj for pgsql-hackers@postgresql.org; Tue, 22 Oct 2024 14:54:49 +0000 Received: from karst (82-65-23-130.subs.proxad.net [82.65.23.130]) by mail.dalibo.com (Postfix) with ESMTPSA id E552927CD2; Tue, 22 Oct 2024 16:54:45 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=dalibo.com; s=a; t=1729608886; bh=A3DoTQ4/OSIrfUOGRrWfOxnIi+SQlI6vXij8/kkjFBk=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=VVZv45Qg/GRGafn6XRlmpFhzQ3gV27MiKsNFXrqXz2UCKTVJ6IB/a0siXrE3Xr9gf 2yGtP2Lkr2NUMwFXPbJ4LYKPG5sL1xgjVTYNxMPX3Ubyjg2zeCLrH7NZVVxyJmFWjl 70d5yFL1qiPPMzeVcTNgt7y34cVTxQd235vBHpPY= Date: Tue, 22 Oct 2024 16:54:45 +0200 From: Jehan-Guillaume de Rorthais To: Alvaro Herrera Cc: Tender Wang , Junwang Zhao , "pgsql-hackers@postgresql.org" , Alexander Lakhin , Guillaume Lelarge , Michael Paquier Subject: Re: [BUG] Fix DETACH with FK pointing to a partitioned table fails Message-ID: <20241022165445.23b3b712@karst> In-Reply-To: <202410212152.ppnqfvqvxu3z@alvherre.pgsql> References: <202410212152.ppnqfvqvxu3z@alvherre.pgsql> Organization: Dalibo MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Mon, 21 Oct 2024 23:52:18 +0200 Alvaro Herrera wrote: > On 2024-Oct-21, Tender Wang wrote: >=20 > > I suspect that we don't need the below if > > statement anymore. > > /* > > * If the referenced side is partitioned (which we know because our > > * parent's constraint points to a different relation than ours) then > > * we must, in addition to the above, create pg_constraint rows that > > * point to each partition, each with its own action triggers. > > */ > > if (parentConForm->conrelid !=3D conform->conrelid) > > { > > ... > > } > >=20 > > The above contidion is always true according to my test. > > I haven't figured out an anti-case. =20 >=20 > You're right, this is useless, we can remove the 'if' line. I kept the > block though, to have a place for all those local variable declarations > (otherwise the code looks messier than it needs to). I'm confused the original patch was considering the trigger creation on the referenced side ONLY when it was partitioned, which was the point of this conditional block (as the comment said), no matter if the test was alw= ays true or not. Maybe this was a leftover of some refactoring=E2=80=A6 > I also noticed that addFkRecurseReferenced() is uselessly taking a List > **wqueue argument but doesn't use it, so I removed it (as fallout, other > routines don't need it either, especially DetachPartitionFinalize). I > added some commentary on the creation of dependencies in > addFkConstraint(). Good catch. Looking at this, on a side note, I realize now addFkRecurseReferenced() and addFkRecurseReferencing() are not exactly mirroring each other as the later is doing more than the former. Either this is fine, or maybe this is the sign something might need some refactoring as addFkRecurseReferencing() carry more than it should. I'm not= sure it deserve more than a comment for futur work/study, if only this is justif= ied. Regards,