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 1sHHE3-005Tkd-A2 for pgsql-bugs@arkaria.postgresql.org; Wed, 12 Jun 2024 06:12:52 +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 1sHHE0-00Dejp-GV for pgsql-bugs@arkaria.postgresql.org; Wed, 12 Jun 2024 06:12:49 +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 1sHHDy-00Dejh-VV for pgsql-bugs@lists.postgresql.org; Wed, 12 Jun 2024 06:12:49 +0000 Received: from wfout8-smtp.messagingengine.com ([64.147.123.151]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sHHDw-000uPM-Er for pgsql-bugs@lists.postgresql.org; Wed, 12 Jun 2024 06:12:46 +0000 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailfout.west.internal (Postfix) with ESMTP id DF7051C00099; Wed, 12 Jun 2024 02:12:41 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Wed, 12 Jun 2024 02:12:42 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paquier.xyz; h= cc:cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm1; t=1718172761; x=1718259161; bh=eSSyr8Ofmv LoCMSZJnjbZQPAMlRcOSdLo5TjDH33oRw=; b=hGiRqzgTfDypFTzwMcDbFVxuFr syovckhiVUUTCl99iBWYjmf9Qn4FsmEHU/w8SdLB5AHiTKa8mZ1N/YKMPgeUqtKR G57HvlfdMIFaGTfjUqXwt3zy3fIvbsWxsEEYT49tmzZE4c3XZJw/5K12JaaG0SXa 4FJp9/JVBBZ575i3spYa2qPEBJHjnBufeYN94qEO/xumnh1+nEslxnIupW5y8oRl 7FqniXKnS+UAnm/YGCwLwyf2peEzmKh1/B97aO0hyhkHPgB1iqmSOSOlxwts/TI3 SjDO/FnIeiB27yHowZX0jtbi5HDfCxCKbRsLGvPVC8GGAvg+eyjN1iBIcNag== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; t=1718172761; x=1718259161; bh=eSSyr8OfmvLoCMSZJnjbZQPAMlRc OSdLo5TjDH33oRw=; b=GC+Cac66T+MNGkbTB6IwHuqKdNNrGwk+Tk3D5RQdMRxy VxNTvMCLTKej1wsUlxZxaQkUgA0cElkzH/GgRdE0aEepfijQChe6LAt2buOCeg3g TQWXJ3lL/WiqtatMizFcWkO47luhNZEpXq5wRQ8kDd6zNsM9LDeJSIRIcP/e5hJl wz1Fx04sXuxipD4cYRSoNvfVzRWwxD6yo1VfMWq7ovrRf2QqazRf2qvFmvvR+Fn7 cRl6YxZHr785xAnCMx6t7cSYKgKoBTh9TFuXJohM2zaJbIiGGJoYki4YObvxytDn y/PbLh8PT770OVaQKz7IZBmQ+fT+MBuscrL80FOqGA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrfedufedguddtvdcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enfghrlhcuvffnffculdejtddmnecujfgurhepfffhvfevuffkfhggtggujgesghdtreer tddtvdenucfhrhhomhepofhitghhrggvlhcurfgrqhhuihgvrhcuoehmihgthhgrvghlse hprghquhhivghrrdighiiiqeenucggtffrrghtthgvrhhnpeetleeifedufffhhfdtteel geeggeffhfekueevteeigfduudevudetgfegiedvjeenucevlhhushhtvghrufhiiigvpe dtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehmihgthhgrvghlsehprghquhhivghrrdig hiii X-ME-Proxy: Feedback-ID: i0fe9450f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 12 Jun 2024 02:12:39 -0400 (EDT) Date: Wed, 12 Jun 2024 15:12:31 +0900 From: Michael Paquier To: Tender Wang Cc: 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: References: <18500-62948b6fe5522f56@postgresql.org> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="lf+TnQYDYXbknopl" Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --lf+TnQYDYXbknopl Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, Jun 12, 2024 at 01:49:32PM +0800, Tender Wang wrote: > Hi, all >=20 > 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; >=20 > 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. > I look through the DetachPartitionFinalize(). The logic of detach indexes > finds a pg_inherits tuple, > then it goes to detach the constraint between parent and child. But in > AttachPartitionEnsureIndexes(), > it check whether constraint of parent is valid or not. If it is valid, th= en > the code will build constraint > connection between parent and child. >=20 > I think we can do this check in DetachPartitionFinalize(). We skip to > detach the constraint if parent actually > does not have one. I try to fix theses issue in attached patch. Are you sure that this is correct? This still makes "tp_pkey" a partition of "t_a_idx" while the parent table "t" has no constraint equivalent to "tp"'s primary key. It seems to me that the correct answer in your command sequence is to *not* make "tp_pkey" a partition of the partitioned index "t_a_idx", and leave it alone. Attaching "tp_pkey" as a partition of "t_a_idx" is only OK as long as this index is used in a constraint equivalent to "tp_pkey". Having a PK on a partition while the parent does not have one is covered by a regression test in indexing.sql (see "Constraint-related indexes" and "primary key on child is okay"). -- Michael --lf+TnQYDYXbknopl Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEG72nH6vTowiyblFKnvQgOdbyQH0FAmZpPE8ACgkQnvQgOdby QH04BBAAjyoECLocAYnvs8g5PvBvj8QkFZxoQuV1yjDeedS4Eo8fu0WwUhFNfhUG FSqfTKLy46U4JJ4x0bYXoLymyG8E+gV852mQW//ZFp6FcTOTMge+ryPq+eTEFInT Cacq1DLPA35dWizIxG8P24B7wlXXFus3GzM3PqEjQ/258Dvr00xRnem/clOwlnMi 1TlCxGbcBzanOAHOtj+gVjpLZyk85+0aIzbnhyqxhwnWkmEhHUaxNn80X6lGLyRf mixnCw6ss3lNEnghW1AK4UuVPhIVRZ+/pUxDNUtdS4MTYPch7vGnFytHGeLlUxkw kTRPHbX6wdu3EjVMCJ0ApivC4ED8vaGwmkLBwsWF3j3GPBb+mY+0XZpp2/Qq7H06 Dr3IAphptBvgWTLbscHQcsAz+r+IPEEi2XfYExq+bqHtlLvcsqvePKQZMjx4pcYx ATNGfP8gE4xnUgpFW+u+OOyKIlD+042F6/Cox0a2CFVfcpShCPZDDYMI1SBotd+s M7+nerkChOOHcE4llnT6v5eNxaXWdMR0MkQBHAbM/GKxi2yNNLg3HBWb8BjdvHqw 02m3+yFVso3dmLTXYJVbaFRzlBdVXBz7acXDj5t7474UTGLFajqc4iJPTrD+PCe8 /NdYxUQHMf2+7GtGmQH2IJ5lqVGJFUNCZeiwuYwqRg//6dxzorg= =Sb8i -----END PGP SIGNATURE----- --lf+TnQYDYXbknopl--