pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Kamil Monicz <kamil@monicz.dev>
Cc: pgsql-bugs@lists.postgresql.org
Subject: Re: BUG #19106: Potential regression with CTE materialization planning in Postgres 18
Date: Mon, 10 Nov 2025 12:09:20 -0500
Message-ID: <1886977.1762794560@sss.pgh.pa.us> (raw)
In-Reply-To: <b23b48b7-0222-4b5e-a986-1d79920a7298@app.fastmail.com>
References: <19106-9dd3668a0734cd72@postgresql.org>
	<1650412.1762703636@sss.pgh.pa.us>
	<b23b48b7-0222-4b5e-a986-1d79920a7298@app.fastmail.com>

"Kamil Monicz" <kamil@monicz.dev> 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





view thread (15+ messages)  latest in thread

Message-ID: <1886977.1762794560@sss.pgh.pa.us>
Permalink:  ../1886977.1762794560@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/1886977.1762794560@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-bugs@postgresql.org
  Cc: tgl@sss.pgh.pa.us, kamil@monicz.dev, pgsql-bugs@lists.postgresql.org
  Subject: Re: BUG #19106: Potential regression with CTE materialization planning in Postgres 18
  In-Reply-To: <1886977.1762794560@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox