Re: Remove useless GROUP BY columns considering unique index

jian he <jian.universality@gmail.com>

From: jian he <jian.universality@gmail.com>
To: Andrei Lepikhov <lepihov@gmail.com>
Cc: David Rowley <dgrowleyml@gmail.com>, Zhang Mingli <zmlpostgres@gmail.com>, PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Date: 2024-11-29T07:04:16Z
Lists: pgsql-hackers

Attachments

On Fri, Nov 29, 2024 at 2:36 PM Andrei Lepikhov <lepihov@gmail.com> wrote:
>
> > I forgot to do a local commit before sending v8. Fixed in the attached v9.
> 1. Thread reference in the patch comment doesn't work.
fixed.

I found that unique expression index can also be used for groupby
column removal.
so I implemented it, aslo added two tests on it.

now remove_useless_groupby_columns like:
  if (index->indexprs == NIL)
  {
    --handle unique index
  }
  else
  {
    --handle unique expression index
  }

what do you think?

Commits

  1. Detect redundant GROUP BY columns using UNIQUE indexes

  2. Defer remove_useless_groupby_columns() work until query_planner()