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 1ri0Gq-00EZ4P-RB for pgsql-bugs@arkaria.postgresql.org; Wed, 06 Mar 2024 23:01:57 +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 1ri0Gp-00FXXA-FE for pgsql-bugs@arkaria.postgresql.org; Wed, 06 Mar 2024 23:01:55 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1ri0Gp-00FXX2-77 for pgsql-bugs@lists.postgresql.org; Wed, 06 Mar 2024 23:01:55 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1ri0Gn-003A09-92 for pgsql-bugs@lists.postgresql.org; Wed, 06 Mar 2024 23:01:55 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 426N1okv387721; Wed, 6 Mar 2024 18:01:50 -0500 From: Tom Lane To: Michael Paquier cc: Tender Wang , pgsql-bugs@lists.postgresql.org, Alexander Lakhin , jian he Subject: Re: BUG #18314: PARALLEL UNSAFE function does not prevent parallel index build In-reply-to: References: <162802.1709746091@sss.pgh.pa.us> Comments: In-reply-to Michael Paquier message dated "Thu, 07 Mar 2024 07:40:57 +0900" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <387719.1709766110.1@sss.pgh.pa.us> Date: Wed, 06 Mar 2024 18:01:50 -0500 Message-ID: <387720.1709766110@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Michael Paquier writes: > Still the issue fixed here and the issue of the other thread are > different? Relying on the relcache tricks the planner to spawn > workers for nothing because they would just fail if the internals of > the function are unsafe to run in the workers, and the function is > marked as such. Sure, but the current patch just trades one set of errors for others. As I said, if we care about this problem then the right fix will involve serializing/deserializing already-const-folded expression trees instead of expecting that the workers can regenerate those. I don't personally think it's worth the trouble, especially not if we can get rid of the need for exception-using functions to be marked parallel unsafe. > In some cases users like to use properties as hints > to give to the planner about what to use or not. I'd like to believe > (and perhaps that's a cute thought) that functions are marked as > parallel-unsafe for a purpose, which is that they cannot run in > workers as they rely on a shared state. Whether the internals of the > functions are implemented correctly is up to the user. I mean, it's > perfectly possible to mark a function as immutable while its internals > are volatile, and I've seen people rely on that to push down clauses. It's the other direction that I'm concerned about: if we inline a SQL function and find that its innards are less volatile than the original marking, we are free to exploit that, and people will complain if we don't. Similarly, if the innards are more parallel safe than the original marking, we should be able to exploit that. regards, tom lane