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 1pXogX-0001Vb-CI for pgsql-hackers@arkaria.postgresql.org; Thu, 02 Mar 2023 19:33:49 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pXogU-0000sd-Gf for pgsql-hackers@arkaria.postgresql.org; Thu, 02 Mar 2023 19:33:46 +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 1pXogU-0000sU-7f for pgsql-hackers@lists.postgresql.org; Thu, 02 Mar 2023 19:33:46 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pXogN-0001dp-LW for pgsql-hackers@postgresql.org; Thu, 02 Mar 2023 19:33:45 +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 322JXZ4T2129738; Thu, 2 Mar 2023 14:33:36 -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: <20230225214401.346ancgjqc3zmvek@awork3.anarazel.de> References: <20230225214401.346ancgjqc3zmvek@awork3.anarazel.de> Comments: In-reply-to Andres Freund message dated "Sat, 25 Feb 2023 13:44:01 -0800" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <2129736.1677785615.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Thu, 02 Mar 2023 14:33:35 -0500 Message-ID: <2129737.1677785615@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Andres Freund writes: > Around > https://www.postgresql.org/message-id/20230224015417.75yimxbksejpffh3%40= awork3.anarazel.de > I suggested that we should evaluate the arguments of correlated SubPlans= as > part of the expression referencing the subplan. > Here's a patch for that. I looked through this, and there is one point that is making me really uncomfortable. This bit is assuming that we can bind the address of the es_param_exec_vals array right into the compiled expression: + ParamExecData *prm =3D &estate->es_param_exec_vals[paramid]; + + ExecInitExprRec(lfirst(pvar), state, &prm->value, &prm->isnull); Even if that works today, it'd kill the ability to use the compiled expression across more than one executor instance, which seems like a pretty high price. Also, I think it probably fails already in EvalPlanQual contexts, because EvalPlanQualStart allocates a separate es_param_exec_vals array for EPQ execution. I think we'd be better off inventing an EEOP_SET_PARAM_EXEC step type that is essentially the inverse of EEOP_PARAM_EXEC/ExecEvalParamExec, and then evaluating each parameter value into the expression's scratch Datum/isnull fields and emitting SET_PARAM_EXEC to copy those to the correct ParamExecData slot. regards, tom lane