Re: remove_useless_joins vs. bug #19560

From: Ayush Tiwari <ayushtiwari(dot)slg01(at)gmail(dot)com>
To: Richard Guo <guofenglinux(at)gmail(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: remove_useless_joins vs. bug #19560
Date: 2026-10-03 18:43:33
Message-ID: CAJTYsWXTb6dw=R8ayMHoiV==tkM0CVO6oTC-0TOCVrCRhVYS0Q@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

On Fri, 25 Sept 2026 at 17:13, Ayush Tiwari <ayushtiwari(dot)slg01(at)gmail(dot)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 Content-Type Size
v1-0001-Don-t-reprocess-PHV-copies-within-outer-level-agg.patch application/octet-stream 7.4 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2026-10-03 18:51:00 Re: Coverage with make coverage-html is broken on latest Debian using lcov v2
Previous Message Andres Freund 2026-10-03 18:22:12 Re: Regression tests failures due to concurrent grants