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 1uJxfV-00AGHl-2B for pgsql-general@arkaria.postgresql.org; Tue, 27 May 2025 17:00:49 +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 1uJxfR-009bAc-1l for pgsql-general@arkaria.postgresql.org; Tue, 27 May 2025 17:00:45 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1uJxfQ-009bAF-H0 for pgsql-general@lists.postgresql.org; Tue, 27 May 2025 17:00:44 +0000 Received: from fhigh-b5-smtp.messagingengine.com ([202.12.124.156]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1uJxfO-000EWv-2K for pgsql-general@lists.postgresql.org; Tue, 27 May 2025 17:00:43 +0000 Received: from phl-compute-01.internal (phl-compute-01.phl.internal [10.202.2.41]) by mailfhigh.stl.internal (Postfix) with ESMTP id 4FCBE254013E; Tue, 27 May 2025 13:00:41 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-01.internal (MEProxy); Tue, 27 May 2025 13:00:41 -0400 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=fm1; t=1748365241; x=1748451641; bh=Q ADdTwY9/+dd68BdMeZ+tfuGQsbXE5bAJsxLTIkJsvo=; b=GIg19jbSrZ8/LSh5j /6gPJzXe483wEUgP+kY6vmc7Mwd0EG2oPbonrHlGNgHngXcZJoUZ3OmYxmtzIOb9 sK+4Fd+snkmQ3GBJ1hmFLEJdH876CZdS8o9LwPRtgb3M7RPFOjh4iRxwziJy5FzH 58FXh+10qRO3SLjApyeKWbtR3tMGDeoRm4L76X+67RO7MmaT2kyrXpnH3xX0qofA UX3AzzSmIQEwTvQ0Vhh/y7LMUBStcWfm6e2WS3EdWiZvfvD4qqctzCKSiaGgzxs2 7bBKdPecyIVwCZTB6pI8yAqeTMIC3DqQRv7EdedHRoaU4VBD/TyZ5Dz4/jNsnsle lE3tw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtddtgddvtdelvdculddtuddrgeefvddrtd dtmdcutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpggft fghnshhusghstghrihgsvgdpuffrtefokffrpgfnqfghnecuuegrihhlohhuthemuceftd dtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpeffhffvvefukfgg tggugfgjsehtkeertddttdejnecuhfhrohhmpeetlhhvrghrohcujfgvrhhrvghrrgcuoe grlhhvhhgvrhhrvgesrghlvhhhrdhnohdqihhprdhorhhgqeenucggtffrrghtthgvrhhn pedvkedtffduffdtffffheffhfejjefhgfeiueeukeejkeffgfdufffhudffffeuveenuc ffohhmrghinhepvghnthgvrhhprhhishgvuggsrdgtohhmnecuvehluhhsthgvrhfuihii vgeptdenucfrrghrrghmpehmrghilhhfrhhomheprghlvhhhvghrrhgvsegrlhhvhhdrnh hoqdhiphdrohhrghdpnhgspghrtghpthhtohepgedpmhhouggvpehsmhhtphhouhhtpdhr tghpthhtoheprggurhhirghnrdhklhgrvhgvrhesrghklhgrvhgvrhdrtghomhdprhgtph htthhopehprghulhdrfhhovghrshhtvghrsehgmhgrihhlrdgtohhmpdhrtghpthhtohep phhgshhqlhdqghgvnhgvrhgrlheslhhishhtshdrphhoshhtghhrvghsqhhlrdhorhhgpd hrtghpthhtohepthhglhesshhsshdrphhghhdrphgrrdhush X-ME-Proxy: Feedback-ID: ia2694551:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 27 May 2025 13:00:39 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alvh.no-ip.org; s=schmee; t=1748365237; bh=mLo2slqsEG4rEY8MxeVjfCaMWWcUFcbjAJXgJdyWlnU=; h=Date:From:To:Cc:Subject:In-Reply-To:From; b=SiFAgbpr6MXYK7BnqGgYJz2/GGgpPr/ubbl1vJjfAnLV+rAa4HVJWk084sRdfXyYO NpUAxFPBdZQKXcTnzAqMut4Bq0XIiDxjW4xNtSNxTuQ418KQlXO6+NfE3rYL3+7DC0 wVtzl7xagc3KVSs+82aIewdmx+hgwYZYj4QDwAb08+/ZTwBSyvUs7fN9sQZEKt7JR2 UYh/4FI5uEleW+KHX4Bf0qszd4LsAahs1k9m0ZY0Hs8+ox6hgsTs07P8tAw0/uCfDC 8F0UJU3mioLYzvq6Gb4XR4Z0QKZXj4H5o1A+PKIL6G+whEfG6NyuKThfl3jBBIVjRB usD/Qpujfw0fg== Received: by schmee.alvh.no-ip.org (Postfix, from userid 1000) id 7B04C90; Tue, 27 May 2025 13:00:37 -0400 (EDT) Date: Tue, 27 May 2025 19:00:37 +0200 From: Alvaro Herrera To: Tom Lane Cc: Paul Foerster , Adrian Klaver , pgsql-general list Subject: Re: PostgreSQL 15.10 update corrective action for ATTACH PARTITION/DETACH PARTITION Message-ID: <202505271700.ux5k6b3tv5fz@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <202411291715.lwona3kp2xvv@alvherre.pgsql> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hello, Belatedly, I came back to this issue in the release notes. Here's a query for correctly reporting the problem and not reporting the cases where there isn't a problem: SELECT conrelid::pg_catalog.regclass AS "constrained table", conname AS constraint, confrelid::pg_catalog.regclass AS "references", pg_catalog.format('ALTER TABLE %s DROP CONSTRAINT %I;', conrelid::pg_catalog.regclass, conname) AS "drop", pg_catalog.format('ALTER TABLE %s ADD CONSTRAINT %I %s;', conrelid::pg_catalog.regclass, conname, pg_catalog.pg_get_constraintdef(oid)) AS "add" FROM pg_catalog.pg_constraint c WHERE contype = 'f' AND conparentid = 0 AND (SELECT count(*) FROM pg_catalog.pg_constraint c2 WHERE c2.conparentid = c.oid) <> ((SELECT count(*) FROM pg_catalog.pg_inherits i WHERE (i.inhparent = c.conrelid OR i.inhparent = c.confrelid) AND EXISTS (SELECT 1 FROM pg_catalog.pg_partitioned_table WHERE partrelid = i.inhparent)) + CASE WHEN pg_partition_root(conrelid) = confrelid THEN (SELECT count(*) FROM pg_catalog.pg_partition_tree(confrelid) WHERE level = 1) ELSE 0 END); The difference from the query that's currently in the release notes is that here we count the number of direct partitions of the referenced table and expect that there be exactly that number of additional constraint entries in a self-referential FK, compared to the situation where the FK references a different table. (The query I suggested previously in this thread had a "+1" instead of adding the number of partitions, which obviously works correctly only in one particular case.) I tested this using Paul's scenario, and a few more, and as far as I can tell, it is correct. I'm going to fix the query in the release notes for all past branches now, to avoid confusing people upgrading in the future ... hopefully not many, but I don't think it's going to be zero people. Regards -- Álvaro Herrera Breisgau, Deutschland — https://www.EnterpriseDB.com/ "Para tener más hay que desear menos"