Re: remove_useless_joins vs. bug #19560 - Mailing list pgsql-hackers

From Ayush Tiwari
Subject Re: remove_useless_joins vs. bug #19560
Date
Msg-id CAJTYsWXTb6dw=R8ayMHoiV==tkM0CVO6oTC-0TOCVrCRhVYS0Q@mail.gmail.com
Whole thread
In response to Re: remove_useless_joins vs. bug #19560  (Ayush Tiwari <ayushtiwari.slg01@gmail.com>)
List pgsql-hackers
Hi,

On Fri, 25 Sept 2026 at 17:13, Ayush Tiwari <ayushtiwari.slg01@gmail.com> wrote:
>
> Hi,
>
> Could there be one more case here with a PHV inside an outer-level
> aggregate? On master at e27f3b2cad7, after bee81f78646, this still
> trips an assertion:
>
>     create table t (a int);
>
>     explain (verbose, costs off)
>     select (select sum(ss.c) from t i offset 0)
>     from (select (select s.a) as c from t s) ss
>          right join t o on true;
>
>     TRAP: failed Assert("!IsA(node, SubPlan)"), File: "subselect.c"
>
> IIUC, build_subplan() already leaves a bare PHV argument alone, but
> an Aggref argument can contain the same preprocessed PHV. Walking
> the Aggref seems to enter that PHV again and reach the SubPlan
> created earlier.
>
> Would it make sense to skip PHVs during that argument walk too,
> while still processing other SubLinks in the argument? The attached
> patch tries that, with small tests for sum() and GROUPING().
>
> I haven't seen a wrong result or crash without assertions though.

Resending attachment for commitfest entry.

Regards,
Ayush

Attachment

pgsql-hackers by date:

Previous
From: Andres Freund
Date:
Subject: Re: Regression tests failures due to concurrent grants
Next
From: Tom Lane
Date:
Subject: Re: Coverage with make coverage-html is broken on latest Debian using lcov v2