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 1vd9TM-00EaoM-2M for pgsql-bugs@arkaria.postgresql.org; Tue, 06 Jan 2026 15:59:53 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vd9TK-008woD-1B for pgsql-bugs@arkaria.postgresql.org; Tue, 06 Jan 2026 15:59:51 +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 1vd9TK-008wo5-0M for pgsql-bugs@lists.postgresql.org; Tue, 06 Jan 2026 15:59:50 +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 1vd9TI-004v7K-0x for pgsql-bugs@lists.postgresql.org; Tue, 06 Jan 2026 15:59:50 +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 606Fxfxi1588385; Tue, 6 Jan 2026 10:59:41 -0500 From: Tom Lane To: David Rowley cc: redraiment@gmail.com, pgsql-bugs@lists.postgresql.org, Andres Freund Subject: Re: BUG #19370: PG18 returns incorrect array slice results when slice bounds depend on another array expression In-reply-to: References: <19370-7fb7a5854b7618f1@postgresql.org> Comments: In-reply-to David Rowley message dated "Tue, 06 Jan 2026 22:26:19 +1300" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1588383.1767715181.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Tue, 06 Jan 2026 10:59:41 -0500 Message-ID: <1588384.1767715181@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk David Rowley writes: > On Tue, 6 Jan 2026 at 21:22, PG Bug reporting form > wrote: >> I have encountered a behavioral regression in PostgreSQL 18 related to = array >> slicing when the slice start index is computed from another array expre= ssion >> in the same SELECT list. > Many thanks for the report and reproducer. I've not looked as to why, > but this seems to be caused by a7f107df2. I've included Andres. 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 storing = and * using the value always is in subsequent steps. ExecInitExprRec(arg, state, &state->resvalue, &state->resnull); The comment seems perhaps too airy :-(. I experimented with replacing - &state->resvalue, &state->resnull); + resv, resnull); and indeed that makes the submitted query work --- but it breaks other queries in our regression tests, so it's not a usable solution. I don't see a good reason why ExecInitSubPlanExpr shouldn't be allowed to use state->resvalue/resnull this way. Given that the problem seems specific to array slicing, I'm suspicious that some step in array slicing is failing to cope with input and output datum storage being the same, or something close to that. regards, tom lane