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 CAJTYsWW8THbrnsmYnDqnUgg0PjGrqw2vNOWb8qx7eu191KPW3g@mail.gmail.com
Whole thread
In response to Re: remove_useless_joins vs. bug #19560  (Richard Guo <guofenglinux@gmail.com>)
List pgsql-hackers
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.

Regards,
Ayush

Attachment

pgsql-hackers by date:

Previous
From: Dirkjan Bussink
Date:
Subject: Server crash when describing a FETCH statement after its cursor is closed
Next
From: Matheus Alcantara
Date:
Subject: Re: RI fastpath misses checking EXECUTE on functions