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 1rhLjq-00AzxB-LK for pgsql-bugs@arkaria.postgresql.org; Tue, 05 Mar 2024 03:45:11 +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 1rhLjp-00D36K-4A for pgsql-bugs@arkaria.postgresql.org; Tue, 05 Mar 2024 03:45:09 +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 1rhLjo-00D36C-SB for pgsql-bugs@lists.postgresql.org; Tue, 05 Mar 2024 03:45:09 +0000 Received: from fhigh8-smtp.messagingengine.com ([103.168.172.159]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rhLjk-002u08-Oe for pgsql-bugs@lists.postgresql.org; Tue, 05 Mar 2024 03:45:08 +0000 Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailfhigh.nyi.internal (Postfix) with ESMTP id B363E1140140; Mon, 4 Mar 2024 22:45:03 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Mon, 04 Mar 2024 22:45:03 -0500 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=1709610303; x=1709696703; bh=1g1ceaTNNU pe4/SeNe6lDdWEW0LORbMRsmPLASKY4g0=; b=nr4c99brzA10zgz+k7WCc/11eq MLGYaor5GCKX3IC+XrE22zeUdWJGw7uyh4yfSi7YP4dsPm5Qb97A7LUq1dndwBuY 9P2VxTnoUBFVL/K4QKF4aigl8nTGEoGW5VAhuG8o8L6n2LhYTJ6r+FpGIuZFLkAh c5NVHdKlRj2S6K885Qjj+CFqfJPwHYtiWPi3JfUidz//oBO19pXYA1vnJSdkToIt uZ7bxBy9r4zB/SkeqTF6XisEyojjdOBcGW1idUEgoq1K+AiZSs/HIBJmAu4mFyyf Ov7Fy4khCCuKGCn5BB7jB9PdXkVftSdCZj+nWFJCB7z9VoUKrOzh3r1kIzEQ== 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=1709610303; x=1709696703; bh=1g1ceaTNNUpe4/SeNe6lDdWEW0LO RbMRsmPLASKY4g0=; b=frWVbXa86Pb8837saiFGcgeAVAPfG/SmadNICnVZ5pl4 TZBFRvxCOuGa5haWvqAQZJnxLMRd4vr/m91o6v6jS2+zpxcfXTR6Hp7NodSObBXK zVYYIfhJzAYDCtQd3/5Lm2m/nymf5ru4WCt6Z0/klArwmLsMaLRw1qkbnG3vFyQT 9Pu0NxLtHvwf4lwwjG+eJoZfpJbkBYu1+fqlcK6S0Cy1PwPOU+YsoMLNlUbvlfc5 WH8/UgxTzXiIpMYlyoADQxXoeWoOQBHcv56ry5X6HzYkWVDkf0DS5QxsRkdtUt6C TiOqJd/cnxbrX20YaSczbjMzqIQcokCA057lv5eq9w== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrheekgdeiudcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenfg hrlhcuvffnffculdefhedmnecujfgurhepfffhvfevuffkfhggtggujgesghdtreertddt vdenucfhrhhomhepofhitghhrggvlhcurfgrqhhuihgvrhcuoehmihgthhgrvghlsehprg hquhhivghrrdighiiiqeenucggtffrrghtthgvrhhnpeegffejvefgveduvdejtddvtdei jeehudeuledvudeftdfgfeejvdekveekiedvvdenucffohhmrghinhepphhoshhtghhrvg hsqhhlrdhorhhgnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhf rhhomhepmhhitghhrggvlhesphgrqhhuihgvrhdrgiihii X-ME-Proxy: Feedback-ID: i0fe9450f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 4 Mar 2024 22:45:02 -0500 (EST) Date: Tue, 5 Mar 2024 12:44:43 +0900 From: Michael Paquier To: jian he Cc: Tender Wang , Alexander Lakhin , pgsql-bugs@lists.postgresql.org Subject: Re: BUG #18314: PARALLEL UNSAFE function does not prevent parallel index build Message-ID: References: <18314-5f44050ce33a5492@postgresql.org> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="iwN/rN/xJUAKGiHO" Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --iwN/rN/xJUAKGiHO Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Thu, Feb 29, 2024 at 05:17:41PM +0800, jian he wrote: > if (heap->rd_rel->relpersistence == RELPERSISTENCE_TEMP || > !is_parallel_safe(root, (Node *) RelationGetIndexExpressions(index, true)) || > !is_parallel_safe(root, (Node *) RelationGetIndexPredicate(index, true))) > { > parallel_workers = 0; > goto done; > } Interesting bug. > Overall it looks good. I disagree with this idea. Your patch is creating a shortcut in the relcache code to retrieve data about index predicates and expressions that make it bypass the flattening that would be done in eval_const_expressions(). Giving the option to bypass that in the relcache is a very bad idea, because flattening of the expressions for the planner is not an option: it must happen. So, I fear that your patch could cause bugs if we introduce new code that calls RelationGetIndexExpressions() with an incorrect option. Not documenting the new option is not acceptable either, with only one comment added at the top of plan_create_index_workers(). On top of that, your approach has two bugs: RelationGetIndexExpressions and RelationGetIndexPredicate would return the flattened information if available directly from the relcache, so even if you pass get_raw_expr=true you may finish with flattened expressions and/or predicates, facing the same issues. I think that the correct way to do that would be to get the information from the syscache when calculating the number of parallel workers to use for the parallel index builds, with SysCacheGetAttr(), for example. That would ensure that the expressions are not flattened, letting the relcache be. By the way, this reminds me of 7cce159349cc and its thread for a bug fix that I did for REINDEX CONCURRENTLY a couple of years ago. The mistake is mostly the same: https://www.postgresql.org/message-id/CA%2Bu7OA5Hp0ra235F3czPom_FyAd-3%2BXwSJmX95r1%2BsRPOJc9VQ%40mail.gmail.com -- Michael --iwN/rN/xJUAKGiHO Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEG72nH6vTowiyblFKnvQgOdbyQH0FAmXmlSsACgkQnvQgOdby QH1bORAAmlzL1QzgCG4m84VJEJwdqXVfNbr2fIzX7ydG7IVcN4oHldvUsLbMKTIR fKpxgD3UBiMkBXYJtW3yUTXAe0iLgXai/rPWO+uufqAS6DNU2FkjDbMPGDP0+lWt HWiblvk0Gz770d3CMNPbG1seULIKSWzq3AJur9AX9mSkAKcmNigEf2I8CgfgFjYU o0smM01uhyfF3HAtGPdPSH45KquZOprGphC7sciB5NuF5dyXtzF1gtiu5Xctftd0 f+io0SDnxO9PSPoYbZTBfi5I5+z1VPzdvJKK6Q9phUvdb9Tmo8QKwJagFXB2jCeI uq2NzcnKqGqePCt2bJu1FiSTpdKKgEeFoDX4Md6Tt17hNB0bRGuk6AVYjwl17X2J 88q0wmV6X/u/0JGxhUq5E3/CATMvXwWelirFtQnBN25Cps9LkALssBPtJAsZ6x+n DYzw5G6hVRO7fNviFkElfFW1Lj/T0F+np91JUk+OcdCcpty4KlMa94pxjIsqNZVy Tj3lu961i4ML2Gb6BUpr3/lbdNuYBWKoVAUvUrHJBA0MK0FHbg06bdabE6untghD 8j5gInuAlaAhCjKy5iNCQ26aJHrHGTxY+7S2lHc2G73trZQF/m+Huy0D7G3eQT7w 9gawq61HBhkZhJpHl1SJTpKUbOscbIHGItN6WnXt2VoULmE2AZk= =4cBI -----END PGP SIGNATURE----- --iwN/rN/xJUAKGiHO--