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