Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1qEPCC-0000Zw-Bb for pgsql-bugs@arkaria.postgresql.org; Wed, 28 Jun 2023 07:02:33 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1qEPCB-0002m2-4x for pgsql-bugs@arkaria.postgresql.org; Wed, 28 Jun 2023 07:02:31 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1qEPC9-0002jS-Io for pgsql-bugs@lists.postgresql.org; Wed, 28 Jun 2023 07:02:30 +0000 Received: from wout5-smtp.messagingengine.com ([64.147.123.21]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qEPC5-000sCH-PV for pgsql-bugs@lists.postgresql.org; Wed, 28 Jun 2023 07:02:28 +0000 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.west.internal (Postfix) with ESMTP id E18C032002F9; Wed, 28 Jun 2023 03:02:23 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Wed, 28 Jun 2023 03:02:24 -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:sender :subject:subject:to:to; s=fm2; t=1687935743; x=1688022143; bh=me 5OFKuRMiCC6x2j9cTxeKVKC+T0gkGu37UZJ0cw0mU=; b=fVn9IYuwuWrAPkI8g4 UCw6NgRKtURE+j/+uwU2WL0Kd2ozKkty+ZgyZpKNOq+qexJWAk7NUlVW8pg1fNUW WDDKx3e56G7FewpU4Rf/OJsfvNk9QcrwqoivAwWsyt8SC8Yyaxdk+r+mvCy9AXBu F8Rzg5+WMLjMoWjS3uNNrwSUCfV3wd15m1Nhhyp5dXfWXfGVZ4+XaIr6K8C9WzV6 cVRGFsMyHvmhNc0B2NDUo2O1MluKkkybuFXakq/R4yeb0Aq1ExNmMk2lwjYN9vpv SCTOvJjR4SkySXnbtz92gxwLHa2TPOjQ8gHbjxoq0LPojlY8+jZHHelHO43w9V4T Wtyw== 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:sender:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm2; t=1687935743; x=1688022143; bh=me5OFKuRMiCC6 x2j9cTxeKVKC+T0gkGu37UZJ0cw0mU=; b=qJMnczImXgizIEnZyE1DBCD5+qUeX O4yZYs+Ew1y1kC3ZcGM+E3oSw+5HekHgfNKjSlYHM1848kjeGFjvYxSZ3IqccuFY 9q6GCMYgwBtA7nWT3S2vsxcCB9mkGhBC/AXCm2o+R58L6l5R3Nbrs2RZ+VWe+gsY 1I2OXvYYVyx45fYWdHI592FXsiRc7P/qhQxA5ww4v+egF6NDdksaRGM6Z7jk9yaw gfJTUOV8RM7vuTnVbYyyYNLFuNpfSWsIQ47nlLolh523c56uVGxXRzLSZf0C20+g z7g+nuCgnH9LNZvLbKJmIi8kUvb46QM0s6qR4zMGYwYpPiGENyiP8qHdw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedviedrtddugdduudehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucgfrhhlucfvnfffucdljedtmdenucfjughrpeffhf fvvefukfhfgggtuggjsehgtderredttddunecuhfhrohhmpefoihgthhgrvghlucfrrghq uhhivghruceomhhitghhrggvlhesphgrqhhuihgvrhdrgiihiieqnecuggftrfgrthhtvg hrnhepgfehhefgudefudfgfeelgeeiffegfefhkeefffdvheefuddtheetgeelteevkeet necuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepmhhitg hhrggvlhesphgrqhhuihgvrhdrgiihii X-ME-Proxy: Feedback-ID: i0fe9450f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 28 Jun 2023 03:02:21 -0400 (EDT) Date: Wed, 28 Jun 2023 16:02:15 +0900 From: Michael Paquier To: Alexander Lakhin Cc: Tom Lane , pgsql-bugs@lists.postgresql.org Subject: Re: BUG #17997: Assert failed in validatePartitionedIndex() when attaching partition index to child of valid index Message-ID: References: <17997-a044c27aef95daf8@postgresql.org> <509915.1687704058@sss.pgh.pa.us> <14987634-43c0-0cb3-e075-94d423607e08@gmail.com> <3eaa2c33-2ed1-2996-c6b6-0e7552a64cae@gmail.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="F/pwlVaeN43cP1D5" Content-Disposition: inline In-Reply-To: <3eaa2c33-2ed1-2996-c6b6-0e7552a64cae@gmail.com> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --F/pwlVaeN43cP1D5 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, Jun 28, 2023 at 09:00:00AM +0300, Alexander Lakhin wrote: > There is also another scenario where the new behavior could be > considered as more sensible: > create table t(a int, b int) partition by range (a); > create index on t((a / b)); > create table tp1(a int, b int); > insert into tp1 values (1, 0); > create index concurrently on tp1((a/b)); --=A0 division by zero occurs, b= ut the index is created (as invalid) > alter table t attach partition tp1 for values from (1) to (10); >=20 > Without the fix you get partition tp1_1 attached and the following partit= ion indexes: > Partitioned index "public.t_expr_idx" > btree, for table "public.t" > Partitions: tp1_expr_idx >=20 > Index "public.tp1_expr_idx" > btree, for table "public.tp1", invalid >=20 > But with the patch applied ATTACH PARTITION fails with ERROR: division by= zero. This makes rather sense to me. You cannot really attach the index in this case. And the partition trees are clean. > Though we still can get a partition index chain with invalid indexes > as follows: > create table t(a int, b int) partition by range (a); > create table tp1(a int, b int) partition by range (a); > alter table t attach partition tp1 for values from (1) to (100); > create table tp1_1(a int, b int); > insert into tp1_1 values (1, 0); > create index concurrently on tp1_1((a/b)); -- division by zero occurs, bu= t the index is created (as invalid) > alter table tp1 attach partition tp1_1 for values from (1) to (10); > create index on t((a / b)); Exotic case, leading to this tree: =3D# select indisvalid, relid, parentrelid, isleaf, level from pg_partition_tree('t_expr_idx'), pg_index where indexrelid =3D reli= d; indisvalid | relid | parentrelid | isleaf | level=20 ------------+----------------+--------------+--------+------- t | t_expr_idx | null | f | 0 f | tp1_expr_idx | t_expr_idx | f | 1 f | tp1_1_expr_idx | tp1_expr_idx | t | 2 (3 rows) This looks like a second bug to me in DefineIndex() where we shouldn't even try to link to the invalid index tp1_1_expr_idx, and we should try to create a new index instead. Repeating the last CREATE INDEX command leads to a failure, which is what I'd expect, because we get the computation failure. > It's also interesting that REINDEX for the index tree validates only > a leaf index: > reindex index t_expr_idx; > ERROR:=A0 division by zero REINDEX on a partitioned index only works on the partitions, it does nothing for the partitioned indexes. > So it's not clear (to me, at least), what exactly indisvalid means > for indexes in a partition tree. It seems to me that validatePartitionedIndex() is what defines the use of the flag for partitioned indexes. indisvalid =3D false for a partitioned index means that at least one of its partitions *may* not have a valid index mapping to it, and that it should be switched to true once we are sure that all its partitions have a valid index. indisvalid =3D true on a partitioned table has much a stronger meaning, where all the partitions *have* to have valid indexes. Your first case would follow that, but not the second. For now, I have applied a patch down to v11 to fix the first issue for the partition attaching. Digging into the second one.. -- Michael --F/pwlVaeN43cP1D5 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEG72nH6vTowiyblFKnvQgOdbyQH0FAmSb2vcACgkQnvQgOdby QH1ZjA/+JwhM0Ju3mq5XSjU6hkdPhys0tuzr0qPYTXB8AyebHL1ehg4w9AQBhmUf dCuV1WrQu64jVBkDeh3V/6Ai7DBr13TLxyQIQrvJmywerDIsjkvaNzsdbEWDBpG6 mn5jcdOo40bvS5KpAXBMLSvkZGjhdKqVSQzgy5FyiA+83F62Lxx56V8GG/zgY55m RKDWvFIxWpkTZ3f/Kgc5gLPGpatnWiLXGTz9L+UcRSlKPewJTL4VOts2p1NbVy+P tJGXcAWrhkCnaRlpq5lwiPcegBwahYEVyjifvkBVLLPoldRPzyGySYqEo3vPYUfc 9UIbi+h+DcSQBVNzZ8aF0pGdtiupC55I43tD6qZ6qCfERp1/I/OHw/t1vf5r2IsE doFkG6FnUffl7alFXcJkO6XK+EVV9pYUSGFDzTCtyZyl6JTK6KGJ2F5E9ftW4amn Y9Wxyx+/vEG1S1zNdJMWwpBhSKHradCh3sUoNH3vfD+HrTZX2ucVyzfQwTmEme1J vENfUGq+jhI8ihb7ol9FNXriCfUumT+lv147WA8z5QEk8xm9lo17HcvGA8iedEVm i6y4Fmw3rTNhJSkEX/nCQCFaIz2Rz+rvaKHHSmzYSkVkOeJjJgLegPYRjeKx1Htb jGsDU1SjmQ1n0ve1CYTXaQ6yMdg5iqLDt6VHSERcfy+kX0kgib4= =Sb7C -----END PGP SIGNATURE----- --F/pwlVaeN43cP1D5--