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 1sMu4F-005RFA-4K for pgsql-bugs@arkaria.postgresql.org; Thu, 27 Jun 2024 18:41:59 +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 1sMu4D-00Cg7o-BC for pgsql-bugs@arkaria.postgresql.org; Thu, 27 Jun 2024 18:41:57 +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 1sMu4C-00Cg7e-4Y for pgsql-bugs@lists.postgresql.org; Thu, 27 Jun 2024 18:41:57 +0000 Received: from fhigh7-smtp.messagingengine.com ([103.168.172.158]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sMu48-003rjZ-Sk for pgsql-bugs@lists.postgresql.org; Thu, 27 Jun 2024 18:41:55 +0000 Received: from compute7.internal (compute7.nyi.internal [10.202.2.48]) by mailfhigh.nyi.internal (Postfix) with ESMTP id BF89D11400CE; Thu, 27 Jun 2024 14:41:50 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute7.internal (MEProxy); Thu, 27 Jun 2024 14:41:50 -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-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t=1719513710; x= 1719600110; bh=ti5FGwVWsfeh5gFjKjlENclqN0zemgZKuIzp3eTqtug=; b=L kSIMa23LSkjY6GrTc0pXsX/+yUtWIRcsWbR3+6yxoEBrYJPFaDkom8k2ieAgcY1c g2GtEjR1kQuyxaBMQCV5paVaWyXV2s0+cckUajkMJEwcarfUFDWG6qWjwVRld1XK KcNOrZGVN7wvFoOR8Sf4gd1D7BQIMBhqyaCxsNqJnlKzb93qYoyg3298Ke38Iz/8 Klv2wO36+B5/Yw4On1qCSuHhBIYlHiv2aDDkDibUjnjOKFm7SAvirRJYODkAW4Cx t+H46fybRkdkknCisiOuHHl3E98sPW+cWYwyan1A0ydds4rt+yEiJacKWxehIJ9Z GOwszG7zcHhOfvqAoj7aw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrtdeggdduvdelucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkgggtugfgjgesthekredttddtjeenucfhrhhomheptehlvhgr rhhoucfjvghrrhgvrhgruceorghlvhhhvghrrhgvsegrlhhvhhdrnhhoqdhiphdrohhrgh eqnecuggftrfgrthhtvghrnhepvdektdffudfftdffffehfffhjeejhffgieeuueekjeek fffgudffhfduffffueevnecuffhomhgrihhnpegvnhhtvghrphhrihhsvggusgdrtghomh enucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegrlhhv hhgvrhhrvgesrghlvhhhrdhnohdqihhprdhorhhg X-ME-Proxy: Feedback-ID: ia2694551:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 27 Jun 2024 14:41:50 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alvh.no-ip.org; s=schmee; t=1719513707; bh=ZA2rHITJi8hJMqQ548fkmNYNJWmiex7CPj0PHi7AqOA=; h=Date:From:To:Cc:Subject:In-Reply-To:From; b=KBkj2k0qhEWtbSkP4qM9rQr5gycfqxlxfp1y/0u230KWSwMlaVvILkixI2fql67ZS sKaJz0+ljuRE+Tjb6KOFnbt2WvfOi+ZKrYNEaC3QXByC7235968bpYY0/M4K8L0sf6 dT+2j/pcPa/mrHpG1YmsEhLw/OVjbc6Qai/sx2zvVeBjIG9NxIAczJi9H7Xg4oyvbD UC7W6pDfxJyFDUhnbphrRG9H1Dw3A7IfhhcdbrT/l8AEXEKglvIjhepm8HWZcknVX1 8uiWs5rf9ofYtG1TOR9R0xdPQIdKZGInsoGPxcgP/QADhatrpnZ2j6vQsOWeglRJYZ J38eAEpW4CEjg== Received: by schmee.alvh.no-ip.org (Postfix, from userid 1000) id A923552B; Thu, 27 Jun 2024 11:41:47 -0700 (PDT) Date: Thu, 27 Jun 2024 20:41:47 +0200 From: Alvaro Herrera To: Michael Paquier Cc: Tender Wang , exclusion@gmail.com, pgsql-bugs@lists.postgresql.org Subject: Re: BUG #18500: Detaching a partition with an index manually attached to the parent's index triggers Assert Message-ID: <202406271841.t2bfpwp7tahf@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 2024-Jun-12, Michael Paquier wrote: > On Wed, Jun 12, 2024 at 01:49:32PM +0800, Tender Wang wrote: > > I found another crash case as below: > > CREATE TABLE t (a integer) PARTITION BY RANGE (a); > > CREATE TABLE tp (a integer PRIMARY KEY); > > CREATE UNIQUE INDEX t_a_idx ON t (a); > > ALTER TABLE t ATTACH PARTITION tp FOR VALUES FROM (0) TO (1000); > > ALTER TABLE t DETACH PARTITION tp; > > > > If index of parent is not created by adding constraint, it will trigger > > assert fail. > > The 4th command is I think incorrect to attach "t_a_idx" to "tp"'s > primary key index because "t" does not have an equivalent entry in > pg_constraint. So that does not address the actual issue. Actually, the partition index is attached to the parent index already at CREATE UNIQUE INDEX, so it's the third line that's the problem (but what you say is true too if the user says CREATE UNIQUE INDEX ON ONLY parent). I tend to agree that a good, consistent fix for this would be to forbid a PK in a partition from becoming a child of a non-constraint index in the parent ... A few ereport(ERROR)s sprinkled in various places might be sufficient in the master branch, but perhaps we shouldn't disallow it in stable branches because that might be problematic for existing apps; and I suspect that we'd need to install protections in pg_upgrade to fix databases from earlier branches being upgraded with the given hierarchy (or just prevent the upgrade in --check and tell the users to fix it.) -- Álvaro Herrera 48°01'N 7°57'E — https://www.EnterpriseDB.com/