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 1pYBic-0000Os-0A for pgsql-hackers@arkaria.postgresql.org; Fri, 03 Mar 2023 20:09:30 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pYBia-0008Mj-05 for pgsql-hackers@arkaria.postgresql.org; Fri, 03 Mar 2023 20:09:28 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pYBiZ-0008Ma-NH for pgsql-hackers@lists.postgresql.org; Fri, 03 Mar 2023 20:09:27 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pYBiT-0000lO-4S for pgsql-hackers@postgresql.org; Fri, 03 Mar 2023 20:09:26 +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 323K9I8h2618534; Fri, 3 Mar 2023 15:09:18 -0500 From: Tom Lane To: Andres Freund cc: pgsql-hackers@postgresql.org Subject: Re: Evaluate arguments of correlated SubPlans in the referencing ExprState In-reply-to: <20230303001924.tv7m2jlmb3oro4ab@alap3.anarazel.de> References: <20230225214401.346ancgjqc3zmvek@awork3.anarazel.de> <2129737.1677785615@sss.pgh.pa.us> <20230302200549.l2ikytmnqzvy5a7a@alap3.anarazel.de> <2134061.1677787831@sss.pgh.pa.us> <20230302210031.o4vqzrwu3a2kplko@alap3.anarazel.de> <20230303001924.tv7m2jlmb3oro4ab@alap3.anarazel.de> Comments: In-reply-to Andres Freund message dated "Thu, 02 Mar 2023 16:19:24 -0800" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <2618532.1677874158.1@sss.pgh.pa.us> Date: Fri, 03 Mar 2023 15:09:18 -0500 Message-ID: <2618533.1677874158@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Andres Freund writes: > On 2023-03-02 13:00:31 -0800, Andres Freund wrote: >> I'm not opposed to EXPR_PARAM_SET, to be clear. I'll send an updated >> version later. I was just thinking about the correctness in the current >> world. > Attached. I've looked through this, and it looks basically OK so I marked it RfC. I do have a few nitpicks that you might or might not choose to adopt: It'd be good to have a header comment for ExecInitExprRec documenting the arguments, particularly that resv/resnull are where to put the subplan's eventual result. You could avoid having to assume ExprState's resvalue/resnull being safe to use by instead using the target resv/resnull. This would require putting those into the EEOP_PARAM_SET step so that ExecEvalParamSet knows where to fetch from, so maybe it's not an improvement, but perhaps worth considering. + /* type isn't needed, but an old value could be confusing */ + scratch.d.param.paramtype = InvalidOid; I'd just store the param's type, rather than justifying why you didn't. It's cheap enough and even less confusing. I think that ExecEvalParamSet should either set prm->execPlan to NULL, or maybe better Assert that it is already NULL. It's a bit weird to keep this in ExecScanSubPlan, when the code there no longer depends on it: + Assert(list_length(subplan->parParam) == list_length(subplan->args)); I'd put that before the forboth() in ExecInitSubPlanExpr instead, where it does matter. regards, tom lane