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 1qU7Ci-00Bi21-SG for pgsql-hackers@arkaria.postgresql.org; Thu, 10 Aug 2023 15:04:01 +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 1qU7Ch-00FtHd-As for pgsql-hackers@arkaria.postgresql.org; Thu, 10 Aug 2023 15:03:59 +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 1qU7Ch-00FtHV-0f for pgsql-hackers@lists.postgresql.org; Thu, 10 Aug 2023 15:03:59 +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 1qU7Ce-001i8y-QD for pgsql-hackers@postgresql.org; Thu, 10 Aug 2023 15:03:58 +0000 Received: from karst (larco.ioguix.net [78.202.0.6]) by mail.dalibo.com (Postfix) with ESMTPSA id 021A91F7AE; Thu, 10 Aug 2023 17:03:45 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=dalibo.com; s=a; t=1691679826; bh=LyJ0Vir7aR8wjz8oVXm4vzhqeDwovFyJPDmX1pi5c2E=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=f6leJI/WbnrMQMMpUJN51AaeLH3B24jIy+if+W8Mo50/q4M0snxOOdz6JjK1R24ct VUNnyN7OV/dVndJEMPhBA/tlQbesPmQD5MdjIDAAAy6CQUaVvRLBudfObmPZUDzhLM oewE7jRCeCoLaWkhz5Q1cG/vb1ItfnrHU0TAoMQg= Date: Thu, 10 Aug 2023 17:03:45 +0200 From: Jehan-Guillaume de Rorthais To: Alvaro Herrera Cc: tender wang , "pgsql-hackers@postgresql.org" Subject: Re: [BUG] Fix DETACH with FK pointing to a partitioned table fails Message-ID: <20230810170345.26e41b05@karst> In-Reply-To: <20230803090243.5ba3mapddthv6yhn@alvherre.pgsql> References: <20230803090243.5ba3mapddthv6yhn@alvherre.pgsql> Organization: Dalibo MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Thu, 3 Aug 2023 11:02:43 +0200 Alvaro Herrera wrote: > On 2023-Aug-03, tender wang wrote: > > > I think old "sub-FK" should not be dropped, that will be violates foreign > > key constraint. > > Yeah, I've been playing more with the patch and it is definitely not > doing the right things. Just eyeballing the contents of pg_trigger and > pg_constraint for partitions added by ALTER...ATTACH shows that the > catalog contents are inconsistent with those added by CREATE TABLE > PARTITION OF. Well, as stated in my orignal message, at the patch helps understanding the problem and sketch a possible solution. It definitely is not complete. After DETACHing the table, we surely needs to check everything again and recreating what is needed to keep the FK consistent. But should we keep the FK after DETACH? Did you check the two other discussions related to FK, self-FK & partition? Unfortunately, as Tender experienced, the more we dig the more we find bugs. Moreover, the second one might seems unsolvable and deserve a closer look. See: * FK broken after DETACHing referencing part https://www.postgresql.org/message-id/20230420144344.40744130%40karst * Issue attaching a table to a partitioned table with an auto-referenced foreign key https://www.postgresql.org/message-id/20230707175859.17c91538%40karst