Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hnwhq-0004SY-VH for pgsql-bugs@arkaria.postgresql.org; Thu, 18 Jul 2019 03:03:43 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hnwgr-0006rP-Rr for pgsql-bugs@arkaria.postgresql.org; Thu, 18 Jul 2019 03:02:41 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hnwgr-0006rI-2W for pgsql-bugs@lists.postgresql.org; Thu, 18 Jul 2019 03:02:41 +0000 Received: from out1-smtp.messagingengine.com ([66.111.4.25]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hnwgn-0000vZ-Iy for pgsql-bugs@lists.postgresql.org; Thu, 18 Jul 2019 03:02:40 +0000 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 66F9D21EB2; Wed, 17 Jul 2019 23:02:36 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Wed, 17 Jul 2019 23:02:36 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paquier.xyz; h= date:from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; s=fm2; bh=kEYvJLdGVP6aPLnx5vHnEkQzWYq lUYHDPSES9Q2yH3U=; b=E6Lfq2/qCai5pIWBzJVSLoNDHcPWtHW9EmK6DcvbZAE iGPCkKRB8FLCY68MwC0Wv+eCxtDeGBAGtAknvXilHaN1IpXXvVDAEhaEwqXgWbgs q3fCs3wV1rw19eKnLowpIeSpYqkubcZBPECmbHhbAGCPBcdmLfocqdKPQdiF48p/ ycqkgp4IVWCOwCFWJn1G6n91GVLJ9k1xZaoq/oporm0scqIrTZirJMHkmrOunt4s +/SqpFzaMzMRbp0gjieXnNUis1wvDnmrGMimUqdIdufuvGD2Or0pAvMNt+110y+V niYtMIe++ryWPASyM3mN0ZcElmRy9Khbsl0H4mxgw/Q== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; bh=kEYvJL dGVP6aPLnx5vHnEkQzWYqlUYHDPSES9Q2yH3U=; b=bvr0mktZEIXt6tfduKjxMx ayu9h+nwQ3tylotXZw+mhf9WMqrG7iFAu9poct4FltOA+SNVXfYubTvzCTcH2k3H 4CqqfZINWG1UestAg64R/I0JwgoyByq6F3G7oEazHErUQmby++Vb5JpzWva18RKP ShCjBYWCegRE/fG6/5eUzNtNA07VcboluR+ADIzGNUrFDo2u475i/TuXyOxC3Lu7 /EkgPKZH3GU/PVvKeFNOVAVDWng1fiz3qi88/DCGklD1kfU9/EAxF5roVmlcWFff ueyQsgWKikg+/F+9gclSo4dO+fB946uHrhoTuXjHlKX7lSOBj8kFSOfCpD1VY1Eg == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduvddrieeggdeigecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenfg hrlhcuvffnffculdejtddmnecujfgurhepfffhvffukfhfgggtuggjsehgtderredttddv necuhfhrohhmpefoihgthhgrvghlucfrrghquhhivghruceomhhitghhrggvlhesphgrqh huihgvrhdrgiihiieqnecukfhppeduuddurddutddvrddukedtrddukeehnecurfgrrhgr mhepmhgrihhlfhhrohhmpehmihgthhgrvghlsehprghquhhivghrrdighiiinecuvehluh hsthgvrhfuihiivgeptd X-ME-Proxy: Received: from paquier.xyz (ee0822lan1.rev.em-net.ne.jp [111.102.180.185]) by mail.messagingengine.com (Postfix) with ESMTPA id E7D30380075; Wed, 17 Jul 2019 23:02:34 -0400 (EDT) Date: Thu, 18 Jul 2019 12:02:32 +0900 From: Michael Paquier To: Manuel Rigger Cc: PostgreSQL mailing lists Subject: Re: REINDEX CONCURRENTLY causes ALTER TABLE to fail Message-ID: <20190718030232.GD1416@paquier.xyz> References: MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="Qrgsu6vtpU/OV/zm" Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --Qrgsu6vtpU/OV/zm Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, Jul 17, 2019 at 02:53:54PM +0200, Manuel Rigger wrote: > The REINDEX TABLE CONCURRENTLY causes the ALTER TABLE to fail, which > is unexpected. Without the CONCURRENTLY, the ALTER TABLE works as > expected. When first executing a concurrent reindex, which is followed > by a non-current one, the error still occurs, which might suggest that > the concurrent reindex breaks some internal state. Thanks. The issue comes from the handling of the collation part within the index predicates in pg_index.indpred. I can see a slight difference in the tree with a switch from COLLATE to REFLABEL for example. In your test case, if you actually remove the collation part, this fails similarly: =3D# CREATE UNIQUE INDEX i0 ON t0((1 / t0.c0)) WHERE ('-H') >=3D (t0.c1::TEXT); ERROR: 23505: could not create unique index "i0" DETAIL: Key ((1 / c0))=3D(0) is duplicated. The root of the problem comes from the fact that we rely on BuildIndexInfo() for the index information. This uses RelationGetIndexExpressions() to fetch the set of expressions and=20 RelationGetIndexPredicate() for the predicates. However, the issue is that those routines apply some extra flattening operations for the planner when storing this data in the relation cache, causing the expressions stored in the catalogs for the copy to be changed. So what we store are the expressions that the planner uses. No wonder that this gets broken. There are a couple of approaches that we could do to fix that. The first one I could think about is to change the relcache level so as we don't apply planner-level optimizations when creating a concurrent index entry. Another one, which is less invasive, is to just update the list of expressions and predicates after calling BuildIndexInfo(). Still that means overriding the contents of the relcache with what has been optimized for the planner to what we want to use for the reindex build and I think that this weakens the logic of index_build. -- Michael --Qrgsu6vtpU/OV/zm Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEG72nH6vTowiyblFKnvQgOdbyQH0FAl0v4UgACgkQnvQgOdby QH2rGxAAiuRbottKcPj2OW0xzRZoPLALeCgrOrIYfMzGhDlE0mbwEB4KadnOgLgJ V34Q1LuD3omXhiy6UMpBgK3ZAigp2bKNFK/y4VjET3CnFFvReELOwGRHrFR4iPPE IjLuJ9pzcSlolnmu7lL0C2uR3diYKD7ATMbPaL1J6jaesP42Uw9SnxvUmWYRBma9 SAwmzu6x3OWNyrXaIN3nbgipqVsHkS5nUwTxbigz3qpt7Hw+PXtDpqn/HIWzD95A Mn1g5rMkIv3DoUyWqF4C1bgbXUJDoSFiWt/wFusopvE/RCdvYJEm605P28VZKqWN SQlovCb1j5iowzoE0YET5jRm2B6YdhhPHoY2gf9p4MH5KiblbGUepfolvoFmawhH N/9b8nAJZQwTBJoeQq2U+/ZYGSzK6lwitL4dyzz+nEZFjWC5Gy5E0w+dgCdTqPSb aZJGkgzNTx7bvX+k0hILmIR8wBlBB68xiFLH7ea91cicSC1XWz11M2ueId/VItqI 0icT9NNAmIkQAvRr6qH+z7sPaWTAKUcn7AssrIYsXabCtouDwKyIdMPNhx//okgh UXDiFIofP7t3UANCHxPck/Hw9b8kfnvxaoy1Ql+Pb6Vtw4YvY3Me1x06qB4ecVUh WJG0NSt67QK276mfX8Wd1MqyTyo+OX1ZgLyx+HSm46d1PW1U/7o= =fuuh -----END PGP SIGNATURE----- --Qrgsu6vtpU/OV/zm--