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 1kfCW0-0002ca-Ux for pgsql-hackers@arkaria.postgresql.org; Wed, 18 Nov 2020 01:44:09 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kfCVz-0005Lh-51 for pgsql-hackers@arkaria.postgresql.org; Wed, 18 Nov 2020 01:44:07 +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 1kfCVy-0005LQ-U7 for pgsql-hackers@lists.postgresql.org; Wed, 18 Nov 2020 01:44:06 +0000 Received: from wout5-smtp.messagingengine.com ([64.147.123.21]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kfCVs-0000FC-Hg for pgsql-hackers@lists.postgresql.org; Wed, 18 Nov 2020 01:44:06 +0000 Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.west.internal (Postfix) with ESMTP id B6488ACF; Tue, 17 Nov 2020 20:43:57 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute1.internal (MEProxy); Tue, 17 Nov 2020 20:43:58 -0500 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=fm3; bh=o8bQqhMKaf/ofmcR2e+YhreKCEK ruP094mOh0PM9l2c=; b=a4C2/NBiKgZ03uF7w2x6ThNBfUeJp/8Lp5TeyppBYA4 Fb3QeGHRD0AFX3ExVm0ncipg+buinFSkSkPAdSHY6nYyFvHpCIVEebnjSHn3uDP4 kblB7rNK8SHLPgPV2XBOK8H1ue7GmijhfEMewTvZ0g9xhmD4zWc5nev/8LP5iMgq Oo1Q4sk5fadePq3e0SBMUdaX5I2WyntIGYXLjMWkgVN/1vOWscdmbx3Vrvz9N8Qw SoUles0w7A2Jagjld9hiW5a0oS2m1jMucE4WiiTIR0HvvVNLsJKVG24qlKJa60dT e6HUVFOgL7mBGs6q8BPMCIWU2k+ear7DGnJod8HqY2w== 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=fm1; bh=o8bQqh MKaf/ofmcR2e+YhreKCEKruP094mOh0PM9l2c=; b=B8p5U//OYvaXegx5VU9lb+ qKAYMRp/p1lJT9BIwLfcsG78WAFVEU9lAy949zDKmYsNSD3ciXvcK3XPDPjnF8Ca XuFmCs2Y+Vr2St+WV/P8qggm4g8zIqlNG1rkPdI3SUT+96gHPLyablyEXOnCMnq8 d3uv7HbzTkUDilg5ESSUC8xlT/taqsXBtId+h8oAq2THqzhv4n8do18gjVso9ucW 6oU40/Ls3jO4dX+2uPOhI8UmvxFgP+MeUUf0ClP3REBUQS9wpqGxO7oKMQWVH+BV WEdshqRlWI9HS9pTkCXbaF8OjqAFFzeFRJpcZBzh6N0bnTQ7oMnIG1TV8ewSYpzw == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedujedrudefgedgfeejucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne gfrhhlucfvnfffucdljedtmdenucfjughrpeffhffvuffkfhggtggujgesghdtreertddt vdenucfhrhhomhepofhitghhrggvlhcurfgrqhhuihgvrhcuoehmihgthhgrvghlsehprg hquhhivghrrdighiiiqeenucggtffrrghtthgvrhhnpedvgeduuefhtdeuleettdevjeeh heeiveeuieegleetgeeljeelieeuieehgeevhfenucfkphepudduuddruddtvddrudektd drudekheenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhm pehmihgthhgrvghlsehprghquhhivghrrdighiii 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 37DDC3064AA6; Tue, 17 Nov 2020 20:43:55 -0500 (EST) Date: Wed, 18 Nov 2020 10:43:52 +0900 From: Michael Paquier To: Alvaro Herrera Cc: Dmitry Dolgov <9erthalion6@gmail.com>, Tom Lane , James Coleman , Pg Hackers Subject: Re: remove spurious CREATE INDEX CONCURRENTLY wait Message-ID: <20201118014352.GI19692@paquier.xyz> References: <20201117002341.GA23972@alvherre.pgsql> <20201117171453.GA19701@alvherre.pgsql> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="/8E7gjuj425jZz9t" Content-Disposition: inline In-Reply-To: <20201117171453.GA19701@alvherre.pgsql> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --/8E7gjuj425jZz9t Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Tue, Nov 17, 2020 at 02:14:53PM -0300, Alvaro Herrera wrote: > diff --git a/src/backend/replication/logical/logical.c b/src/backend/replication/logical/logical.c > index f1f4df7d70..4324e32656 100644 > --- a/src/backend/replication/logical/logical.c > +++ b/src/backend/replication/logical/logical.c > @@ -181,7 +181,7 @@ StartupDecodingContext(List *output_plugin_options, > */ > if (!IsTransactionOrTransactionBlock()) > { > - LWLockAcquire(ProcArrayLock, LW_EXCLUSIVE); > + LWLockAcquire(ProcArrayLock, LW_SHARED); > MyProc->statusFlags |= PROC_IN_LOGICAL_DECODING; > ProcGlobal->statusFlags[MyProc->pgxactoff] = MyProc->statusFlags; > LWLockRelease(ProcArrayLock); We don't really document that it is safe to update statusFlags while holding a shared lock on ProcArrayLock, right? Could this be clarified at least in proc.h? > + /* Determine whether we can call set_safe_index_flag */ > + safe_index = indexInfo->ii_Expressions == NIL && > + indexInfo->ii_Predicate == NIL; This should tell why we check after expressions and predicates, in short giving an explanation about the snapshot issues with build and validation when executing those expressions and/or predicates. > + * Set the PROC_IN_SAFE_IC flag in my PGPROC entry. > + * > + * When doing concurrent index builds, we can set this flag > + * to tell other processes concurrently running CREATE > + * INDEX CONCURRENTLY to ignore us when > + * doing their waits for concurrent snapshots. On one hand it > + * avoids pointlessly waiting for a process that's not interesting > + * anyway, but more importantly it avoids deadlocks in some cases. > + * > + * This can only be done for indexes that don't execute any expressions. > + * Caller is responsible for only calling this routine when that > + * assumption holds true. > + * > + * (The flag is reset automatically at transaction end, so it must be > + * set for each transaction.) Would it be better to document that this function had better be called after beginning a transaction? I am wondering if we should not enforce some conditions here, say this one or similar: Assert(GetTopTransactionIdIfAny() == InvalidTransactionId); > + */ > +static inline void > +set_safe_index_flag(void) This routine name is rather close to index_set_state_flags(), could it be possible to finish with a better name? -- Michael --/8E7gjuj425jZz9t Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEG72nH6vTowiyblFKnvQgOdbyQH0FAl+0fFgACgkQnvQgOdby QH3+ig//bQoh3mpMoOIL5dzsuSoE9RBFPRV5PM95y2AsxwvsNclc8G2eYsKulVa2 OHMURfB4f4r1iSI6QPeK2iwzHINImRmwFuAiG+BhfWewjWKI7YZICHWL6qyRreTF 1J2QhuY/HJgH2pyollJ8ihSw4iGCFYnIb/FaolyfOjF+XHh/Jdi3rJMA6XmMYzSJ IrvD6ohwDLuQC7tB6FWTTC6smgJdZjTOZw+n8Mep9+PeOvxdRTb80LY7htljHwDP dJ1hpPwTqbF80Jad4yYC+LF/WORToBhD7JeKeMGLmzBzw0RN41rDkHFm0sesf5Oi EEiBBmOawgkTRkiTnxDDSwax6v5cWJqYEG8NzuBaoEkbPahIwBaZzFxadMEzuqOb Zlb+D8I6hspu5HqhdGZkVX2/5bcT6gvSLQNJ+atDDG+1vNok+Uvy88ltopfGvBm7 /pr0ODPOFxHxrdjpHxZ2KobEPNBRkRiZ7RSM9U+XE1FWgXKAM0XYLUH6/YoNZ7fA 6eovvq2R4oQWNjhM4Nk3nBG2r1GH0XwoLCb/njsAzzun9O8hyYmpgWH4XM7gTIww beftLEUYbwa/It9ILCvUYhQbLF6NEGdN7zVFZinHY/F49Kpd6bA4Sp3bOQ3zeUJ/ JOyWUZ8goSYTQTCqXPTUhndrHZ8yEAddK1QLiSFNkNIQpn73GP0= =MdPs -----END PGP SIGNATURE----- --/8E7gjuj425jZz9t--