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 1vIVOR-003bHG-1J for pgsql-bugs@arkaria.postgresql.org; Mon, 10 Nov 2025 17:09:26 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vIVOP-001lRw-0C for pgsql-bugs@arkaria.postgresql.org; Mon, 10 Nov 2025 17:09:25 +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 1vIVOO-001lRo-2X for pgsql-bugs@lists.postgresql.org; Mon, 10 Nov 2025 17:09:24 +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 1vIVOM-00713C-1N for pgsql-bugs@lists.postgresql.org; Mon, 10 Nov 2025 17:09:24 +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 5AAH9KwK1886978; Mon, 10 Nov 2025 12:09:20 -0500 From: Tom Lane To: "Kamil Monicz" cc: pgsql-bugs@lists.postgresql.org Subject: Re: BUG #19106: Potential regression with CTE materialization planning in Postgres 18 In-reply-to: References: <19106-9dd3668a0734cd72@postgresql.org> <1650412.1762703636@sss.pgh.pa.us> Comments: In-reply-to "Kamil Monicz" message dated "Mon, 10 Nov 2025 04:21:20 +0100" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1886976.1762794560.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Mon, 10 Nov 2025 12:09:20 -0500 Message-ID: <1886977.1762794560@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk "Kamil Monicz" writes: > It's my first time here (and realistically on a proper mailing list), so= please excuse me. Here's the small, self-contained reproduction: Thanks. After a bit of fooling around I was able to convert this to something without any PostGIS dependency: EXPLAIN SELECT * FROM ( SELECT ARRAY[1, 2] AS arr ) r CROSS JOIN LATERAL ( WITH a AS ( SELECT id FROM unnest(r.arr) AS id ), b AS ( SELECT max((SELECT sum(id) FROM a)) AS agg ) SELECT (SELECT agg FROM b) ) s; This worked up until commit b0cc0a71e, and since then it hits an assertion failure in check_agglevels_and_constraints(); or if you don't have asserts enabled then the planner gets confused, because the max() aggregate function is given the wrong agglevelsup. I need to think through what is the correct behavior for cross-CTE references like these. Sadly, this is too late for this week's releases ... regards, tom lane