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.96) (envelope-from ) id 1vdA6N-00Ei4Q-1i for pgsql-bugs@arkaria.postgresql.org; Tue, 06 Jan 2026 16:40:12 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vdA6M-009Dz7-1S for pgsql-bugs@arkaria.postgresql.org; Tue, 06 Jan 2026 16:40:11 +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.96) (envelope-from ) id 1vdA6M-009Dyi-0Z for pgsql-bugs@lists.postgresql.org; Tue, 06 Jan 2026 16:40:10 +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.96) (envelope-from ) id 1vdA6K-004vYB-1k for pgsql-bugs@lists.postgresql.org; Tue, 06 Jan 2026 16:40:10 +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 606Ge18d1593906; Tue, 6 Jan 2026 11:40:01 -0500 From: Tom Lane To: Andres Freund cc: David Rowley , redraiment@gmail.com, pgsql-bugs@lists.postgresql.org Subject: Re: BUG #19370: PG18 returns incorrect array slice results when slice bounds depend on another array expression In-reply-to: <1588384.1767715181@sss.pgh.pa.us> References: <19370-7fb7a5854b7618f1@postgresql.org> <1588384.1767715181@sss.pgh.pa.us> Comments: In-reply-to Tom Lane message dated "Tue, 06 Jan 2026 10:59:41 -0500" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1593904.1767717601.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Tue, 06 Jan 2026 11:40:01 -0500 Message-ID: <1593905.1767717601@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk I wrote: > After re-reading that patch, I suspect an aliasing problem, > specifically from this bit in ExecInitSubPlanExpr: > * ... No > * danger of conflicts with other uses of resvalue/resnull as storin= g and > * using the value always is in subsequent steps. > ExecInitExprRec(arg, state, > &state->resvalue, &state->resnull); Yup, that's it. The problem occurs when a SubPlan is in the subscripts of an array reference. In that case, ExecInitSubscriptingRef has already emitted code to load the source array into its target resv/resnull, which might well be the ExprState's resvalue/resnull. So it's not okay for the array subscript calculation steps to overwrite the ExprState's resvalue/resnull, but ExecInitSubPlanExpr thinks it can. We *could* safely use ExecInitSubPlanExpr's target resv/resnull, but that doesn't line up with EEOP_PARAM_SET's definition: ExecEvalParamSet is hard-wired to store from state->resvalue/resnull. I thought all along that that was probably too simplistic. We could either generalize EEOP_PARAM_SET to include an explicit specification of the source value's address, or insert some kind of LOAD operation to copy the computed value into state->resvalue/resnull. I don't see anything that looks like that today, though. regards, tom lane