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 1poJGV-0002oH-9P for pgsql-hackers@arkaria.postgresql.org; Mon, 17 Apr 2023 07:27:07 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1poJGT-0007N1-3Q for pgsql-hackers@arkaria.postgresql.org; Mon, 17 Apr 2023 07:27:05 +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 1poJGS-0007Ms-OP for pgsql-hackers@lists.postgresql.org; Mon, 17 Apr 2023 07:27:04 +0000 Received: from mail-yb1-xb2e.google.com ([2607:f8b0:4864:20::b2e]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1poJGN-003NXE-Vm for pgsql-hackers@lists.postgresql.org; Mon, 17 Apr 2023 07:27:04 +0000 Received: by mail-yb1-xb2e.google.com with SMTP id k39so2944924ybj.8 for ; Mon, 17 Apr 2023 00:26:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1681716418; x=1684308418; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=Ez1JfA1pxqVJbSQD2k2U8Qj6Exknq3JxSw6Iyqb4beQ=; b=qlJAShIPKrEIUy9Jx3gB9Bz3Q5dy/nN7Oi8Go1HjEXPcFjIKNDCWYlqT3TRRY8V23b x0LclgC26BHQ7Cyukje6PajxBJuk3JB98+fRRcl+83M2BxCx9XFHIDT3oX1+bq+z2VlD wW2Q4dEO7ky2Hnr6k504icb6VO5Ir7HjqPjP1txYzlXPVCvcs3eDOM3RzGwAis17KycB gzERPhq4Pg3kIZ4PjupDZmHH2xjsJ8o0+UfuAkM8MK6yoK2lSIq8MBTAetmvkOt1SRg0 319MMipxw7oSvLrPs2ue8DR9nAwwqtGzVjlMUOPLk1nsopw9S/dyyYseNJUULwNgyqah KWIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681716418; x=1684308418; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Ez1JfA1pxqVJbSQD2k2U8Qj6Exknq3JxSw6Iyqb4beQ=; b=FmEgvkZTiUa4xD1TwG1QBVJLTpUxa4Av1KunH0kezGF6dyqKyKAwPqdlFb4L06ykKC JiTNjRgfXs7+xQ3H2KcnwsVaio/EPhRGJysSYOi9d+2kHW1iU2tIDc8P8j0eTeeAdGFN gyWLjwcMg3uu+nYt0UA23XBnImGgxBfn+QMXD5hDFAExsL0Viz+SlrPLetHAJ4nrLb4L MRD3bCzI8bjzzoJwOudExE/GKpps0Fo6Pv6yBfowhN5YhA0jc+jlV3p1VOsN4Kl5U2rW lD2IrH6ki09Jh5hRwPksYkfsnS8g0t987RM7qf7nW+CZPO6K4ZkAQglYHLgFuKj8e52U O5rA== X-Gm-Message-State: AAQBX9cOjjlWY3tK29HfMBB5QCQH/kj+2kA3APuCnCYsGhA60RDgqXab DrvpwByXg4ABQYKvZv4iDlb/uMjwQENSt/Nz2Z0= X-Google-Smtp-Source: AKy350ZeDb2ZFniF9Djx3MRVszyIWLDMyxdEYlmQRHbb1oM6+mm1tOCZ+kq1it2WvgccHGFXcWE0d/YZas8YqWxh87I= X-Received: by 2002:a25:cfce:0:b0:b8b:fd23:5028 with SMTP id f197-20020a25cfce000000b00b8bfd235028mr8791761ybg.3.1681716417826; Mon, 17 Apr 2023 00:26:57 -0700 (PDT) MIME-Version: 1.0 References: <1129530.1681317832@sss.pgh.pa.us> <1315906.1681394451@sss.pgh.pa.us> In-Reply-To: From: Richard Guo Date: Mon, 17 Apr 2023 15:26:46 +0800 Message-ID: Subject: Re: Allowing parallel-safe initplans To: Tom Lane Cc: pgsql-hackers@lists.postgresql.org Content-Type: multipart/alternative; boundary="000000000000b2925405f9831db8" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000b2925405f9831db8 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Mon, Apr 17, 2023 at 10:57=E2=80=AFAM Richard Guo wrote: > The initPlan has been moved from the Result node to the Gather node. As > a result, when doing tuple projection for the Result node, we'd get a > ParamExecData entry with NULL execPlan. So the initPlan does not get > chance to be executed. And we'd get the output as the default value > from the ParamExecData entry, which is zero as shown. > > So now I begin to wonder if this wrong result issue is possible to exist > in other places where we move initPlans. But I haven't tried hard to > verify that. > I looked further into this issue and I believe other places are good. The problem with this query is that the es/ecxt_param_exec_vals used to store info about the initplan is not the same one as in the Result node's expression context for projection, because we've forked a new process for the parallel worker and then created and initialized a new EState node, and allocated a new es_param_exec_vals array for the new EState. When doing projection for the Result node, the current code just goes ahead and accesses the new es_param_exec_vals, thus fails to retrieve the info about the initplan. Hmm, I doubt this is sensible. So now it seems that the breakage of regression tests is more severe than being cosmetic. I wonder if we need to update the comments to indicate the potential wrong results issue if we move the initPlans to the Gather node. Thanks Richard --000000000000b2925405f9831db8 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

On Mon, Apr 17, 2023 at 10:57=E2=80=AFAM = Richard Guo <guofenglinux@gmai= l.com> wrote:
The initPlan has been mov= ed from the Result node to the Gather node.=C2=A0 As
a result, when doin= g tuple projection for the Result node, we'd get a
ParamExecData ent= ry with NULL execPlan.=C2=A0 So the initPlan does not get
chance to be e= xecuted.=C2=A0 And we'd get the output as the default value
from the= ParamExecData entry, which is zero as shown.

So now I begin to wond= er if this wrong result issue is possible to exist
in other places where= we move initPlans.=C2=A0 But I haven't tried hard to
verify that.

I looked further into this= issue and I believe other places are good.
The problem with this query = is that the es/ecxt_param_exec_vals used to
store info about the initpla= n is not the same one as in the Result
node's expression context for= projection, because we've forked a new
process for the parallel wor= ker and then created and initialized a new
EState node, and allocated a = new es_param_exec_vals array for the new
EState.=C2=A0 When doing projec= tion for the Result node, the current code
just goes ahead and accesses = the new es_param_exec_vals, thus fails to
retrieve the info about the in= itplan.=C2=A0 Hmm, I doubt this is sensible.

So now it seems that th= e breakage of regression tests is more severe
than being cosmetic.=C2=A0= I wonder if we need to update the comments to
indicate the potential wr= ong results issue if we move the initPlans to
the Gather node.

Th= anks
Richard
--000000000000b2925405f9831db8--