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.98.2) (envelope-from ) id 1xURvU-00000000yaC-1U7H for pgsql-bugs@arkaria.postgresql.org; Fri, 20 Nov 2026 16:57:28 +0000 Received: from localhost ([127.0.0.1]:59022 helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.98.2) (envelope-from ) id 1xURvT-0000000AJSq-3IOv for pgsql-bugs@arkaria.postgresql.org; Fri, 20 Nov 2026 16:57:27 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]:54532) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xURvT-0000000AJSh-2Bck for pgsql-bugs@lists.postgresql.org; Fri, 20 Nov 2026 16:57:27 +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.98.2) (envelope-from ) id 1xURvR-00000000mIn-0o1F for pgsql-bugs@lists.postgresql.org; Fri, 20 Nov 2026 16:57:27 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.18.1/8.18.1) with ESMTP id 6AKGvG611533787; Fri, 20 Nov 2026 11:57:16 -0500 DKIM-Filter: OpenDKIM Filter v2.11.0 sss.pgh.pa.us 6AKGvG611533787 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sss.pgh.pa.us; s=default; t=1795193836; bh=IeFS4iE/kesi4L9Dg9IqhKuzL+e9wQm0EnFbfKb2quA=; h=From:To:cc:Subject:In-reply-to:References:Date:From; b=UO/a09+9DpCirE0EYw0fKKayltSmSdFQoGFUU+Ra2SaeLb/tmMfgfZc10kQgE/ryh yBlqWUD/aozrrzTetV0Bq630zI5e7ZpvZsX9OOoi93hqUL1WchzSbqQ7pOjcxcSB2F OytflPwHxzfUt2QC7WrU+LC3uMyzqVkL9rWMwiyY= From: Tom Lane To: Nitin Motiani cc: tharakan@gmail.com, pgsql-bugs@lists.postgresql.org, Peter Eisentraut Subject: Re: BUG #19922: CYCLE/SEARCH with a window in the recursive term: could not find replacement targetlist entry In-reply-to: References: <19922-a0d338245d361a4c@postgresql.org> <1250317.1795124832@sss.pgh.pa.us> Comments: In-reply-to Nitin Motiani message dated "Fri, 20 Nov 2026 16:22:30 +0530" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1533785.1795193835.1@sss.pgh.pa.us> Date: Fri, 20 Nov 2026 11:57:16 -0500 Message-ID: <1533786.1795193836@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Nitin Motiani writes: > On Fri, Nov 20, 2026 at 3:17 AM Tom Lane wrote: >> I think the problem is that rewriteSearchAndCycle() is appending extra >> items to the right subquery's tlist without regard for the possibility >> that there are resjunk items in it. > Thanks for the idea. I checked this and it indeed seemed to be the case. > I'm attaching a patch with the fix in this area. Thanks for doing the legwork. I pushed this after rewriting the initial hunk a little: I didn't like just assuming that we know the number of non-resjunk columns. rewriteTargetListIU() splits the tlist using explicit checks on the resjunk flags, and I think this code should do the same. We can assert that the result matches the CTE column list afterwards. regards, tom lane