Re: Reordering DISTINCT keys to match input path's pathkeys

Richard Guo <guofenglinux@gmail.com>

From: Richard Guo <guofenglinux@gmail.com>
To: Andrei Lepikhov <lepihov@gmail.com>
Cc: PostgreSQL-development <pgsql-hackers@postgresql.org>, David Rowley <dgrowleyml@gmail.com>
Date: 2024-11-13T06:49:59Z
Lists: pgsql-hackers

Attachments

On Mon, Oct 28, 2024 at 6:15 PM Andrei Lepikhov <lepihov@gmail.com> wrote:
> On 6/7/24 16:46, Richard Guo wrote:
> > This patch does not apply any more, so here is a new rebase, with some
> > tweaks to the comments.

> This patch needs a minor rebase again.
> After skimming the code, I want to say that it looks good. But maybe to
> avoid one more *_reordering GUC - it would be better to cover all path
> key reorderings under a single GUC.

Thanks for reviewing this patch.  After some consideration, I think
it's not too complex to also apply this optimization to DISTINCT ON.
The parser already ensures that the DISTINCT ON expressions match the
initial ORDER BY expressions; we just need to ensure that the
resulting pathkey list from the reordering matches the original
distinctClause pathkeys, while leaving the remaining pathkeys
unchanged in order.  Please see attached.

I'm not sure about merging these two 'reordering' GUCs into one.
While they may look similar, they apply to very different scenarios.
However, I'm open to other suggestions.

Thanks
Richard

Commits

  1. Fix test case from a8ccf4e93

  2. Reordering DISTINCT keys to match input path's pathkeys