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 1kiNNV-0001o0-EV for pgsql-hackers@arkaria.postgresql.org; Thu, 26 Nov 2020 19:56:29 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kiNNS-0002EK-Q9 for pgsql-hackers@arkaria.postgresql.org; Thu, 26 Nov 2020 19:56:26 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kiNNR-0002EC-UH for pgsql-hackers@lists.postgresql.org; Thu, 26 Nov 2020 19:56:26 +0000 Received: from out1-smtp.messagingengine.com ([66.111.4.25]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kiNNO-0000O7-Gu for pgsql-hackers@lists.postgresql.org; Thu, 26 Nov 2020 19:56:25 +0000 Received: from compute2.internal (compute2.nyi.internal [10.202.2.42]) by mailout.nyi.internal (Postfix) with ESMTP id 8530F5C00CD; Thu, 26 Nov 2020 14:56:19 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Thu, 26 Nov 2020 14:56:19 -0500 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:subject:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; bh=TrsKzbzpcT+tU6TRH 7dC0THFPicEwS84n7Zer8cEWyY=; b=GrE61LUOY2Z88ZyN0zdnRNuTfzbny+3gL S+VK0XMPswETOIRFevdfMRjuEDKghR0EnnL0ylAwia6MEQ2Sj70FfMAOgaLqvukR WLVJjdhd31jF8nwduyBX+RzKKRsBQ8hVt+d8jjOFImq1liNOkp1c67PY5PVGwBm2 bylVdo2gVVPjX7a/ff22woA9KSivxZoAMvED3cY1ykhg60xaxMYZez69gfOSY88i GPnT40Ar7laRLnLMUeijVF/I/NzZMu3vvdQ0zfI5zKhR3z0aa6PrtqMItTSLti1T SmWXj4PsR4InUXCLGQHmoTKqiS1cdhYsWZJZee35iRqf/qaDW7Hrw== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedujedrudehvddgudeffecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpeffhffvuffkgggtuggjfgesthdtredttdervdenucfhrhhomheptehlvhgr rhhoucfjvghrrhgvrhgruceorghlvhhhvghrrhgvsegrlhhvhhdrnhhoqdhiphdrohhrgh eqnecuggftrfgrthhtvghrnhephfelueefjeejvddvgeegfeetfefgieejiedtueeujedt iefgtddvteeggeekueffnecuffhomhgrihhnpehpohhsthhgrhdrvghsnecukfhppedule dtrdelhedrudekrdejleenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgr ihhlfhhrohhmpegrlhhvhhgvrhhrvgesrghlvhhhrdhnohdqihhprdhorhhg X-ME-Proxy: Received: from perhan.alvh.no-ip.org (unknown [190.95.18.79]) by mail.messagingengine.com (Postfix) with ESMTPA id 72252328005D; Thu, 26 Nov 2020 14:56:18 -0500 (EST) Received: by perhan.alvh.no-ip.org (Postfix, from userid 1000) id C4E262A0ADF; Thu, 26 Nov 2020 16:56:15 -0300 (-03) Date: Thu, 26 Nov 2020 16:56:15 -0300 From: Alvaro Herrera To: Dmitry Dolgov <9erthalion6@gmail.com> Cc: Michael Paquier , James Coleman , Tom Lane , Pg Hackers Subject: Re: remove spurious CREATE INDEX CONCURRENTLY wait Message-ID: <20201126195615.GA1176@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20201109154743.sij6j5ue3j673r7h@localhost> User-Agent: Mutt/1.10.1 (2018-07-13) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk So let's discuss the next step in this series: what to do about REINDEX CONCURRENTLY. I started with Dmitry's patch (an updated version of which I already posted in [1]). However, Dmitry missed (and I hadn't noticed) that some of the per-index loops are starting transactions also, and that we need to set the flag in those. And what's more, in a couple of the function-scope transactions we do set the flag pointlessly: the transactions there do not acquire a snapshot, so there's no reason to set the flag at all, because WaitForOlderSnapshots ignores sessions whose Xmin is 0. There are also transactions that wait first, without setting a snapshot, and then do some catalog manipulations. I think it's prett much useless to set the flag for those, because they're going to be very short anyway. (There's also one case of this in CREATE INDEX CONCURRENTLY.) But there's a more interesting point also. In Dmitry's patch, we determine safety for *all* indexes being processed as a set, and then apply the flag only if they're all deemed safe. But we can optimize this, and set the flag for each index' transaction individually, and only skip it for those specific indexes that are unsafe. So I propose to change the data structure used in ReindexRelationConcurrently from the current list of OIDs to a list of (oid,boolean) pairs, to be able to track setting the flag individually. There's one more useful observation: in the function-scope transactions (outside the per-index loops), we don't touch the contents of any indexes; we just wait or do some catalog manipulation. So we can set the flag *regardless of the safety of any indexes*. We only need to care about the safety of the indexes in the phases where we build the indexes and when we validate them. [1] https://postgr.es/m/20201118175804.GA23027@alvherre.pgsql