From: | Richard Guo <guofenglinux(at)gmail(dot)com> |
---|---|
To: | PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: Allow pushdown of HAVING clauses with grouping sets |
Date: | 2024-10-10 02:23:23 |
Message-ID: | CAMbWs4-1CrTpjOvQgW7Y=J7mX23sAiX9_EtDtQeM7q27EUTaLQ@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
On Wed, Sep 11, 2024 at 11:43 AM Richard Guo <guofenglinux(at)gmail(dot)com> wrote:
> In some cases, we may want to transfer a HAVING clause into WHERE in
> hopes of eliminating tuples before aggregation instead of after.
>
> Previously, we couldn't do this if there were any nonempty grouping
> sets, because we didn't have a way to tell if the HAVING clause
> referenced any columns that were nullable by the grouping sets, and
> moving such a clause into WHERE could potentially change the results.
>
> Now, with expressions marked nullable by grouping sets with the RT
> index of the RTE_GROUP RTE, it is much easier to identify those
> clauses that reference any nullable-by-grouping-sets columns: we just
> need to check if the RT index of the RTE_GROUP RTE is present in the
> clause. For other HAVING clauses, they can be safely pushed down.
>
> I'm not sure how common it is in practice to have a HAVING clause
> where all referenced columns are present in all the grouping sets.
> But it seems to me that this optimization doesn't cost too much. Not
> implementing it seems like leaving money on the table.
I've gone ahead and pushed this.
Thanks
Richard
From | Date | Subject | |
---|---|---|---|
Next Message | Junwang Zhao | 2024-10-10 02:30:06 | Re: general purpose array_sort |
Previous Message | Richard Guo | 2024-10-10 02:18:52 | Re: Why don't we consider explicit Incremental Sort? |