From: Andrei Lepikhov <lepihov@gmail.com>
To: Richard Guo <guofenglinux@gmail.com>
Cc: PostgreSQL-development <pgsql-hackers@postgresql.org>
Cc: David Rowley <dgrowleyml@gmail.com>
Subject: Re: Reordering DISTINCT keys to match input path's pathkeys
Date: Wed, 13 Nov 2024 17:36:10 +0700
Message-ID: <e56a0dbd-c969-4a69-b5c3-b640bc8ebc8a@gmail.com> (raw)
In-Reply-To: <CAMbWs4-SHEBahuQCo7-4yK4=CmEP6jd5RwKbGUB2akFB79mCCQ@mail.gmail.com>
References: <CAMbWs48dR26cCcX0f=8bja2JKQPcU64136kHk=xekHT9xschiQ@mail.gmail.com>
<CAApHDvq39jp0EXbtu0Kwx7um_x54MiFcKx2sNj9kdTc9TEYu7g@mail.gmail.com>
<CAMbWs4-+gBN4sQ7wyEptrsKO1AxJHOocxWQ72=bX1g1=9cOrSA@mail.gmail.com>
<CAMbWs48j2xnk3WpO55dJU-4yoSMRb56=qf=zKPfb5driTwH-Yg@mail.gmail.com>
<CAMbWs49gL-c=xBuQTQcVSMjsAnUhDt1-x6BZHkNskvcVdZ94gw@mail.gmail.com>
<0fc11a92-f6e4-4d8c-b882-91283ef54bce@gmail.com>
<CAMbWs4-SHEBahuQCo7-4yK4=CmEP6jd5RwKbGUB2akFB79mCCQ@mail.gmail.com>
On 11/13/24 13:49, Richard Guo wrote:
> 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.
Thanks, I'll discover it later.
BTW have you ever thought about one more, cost-based reordering strategy?
For now, we can reorder GROUP-BY and distinct clauses according to two
orderings: 1) ORDER-BY order and 2) order derived from the underlying
query tree.
In thread [1], I try to add one more strategy that minimises the number
of comparison operator calls. It seems that it would work the same way
with the DISTINCT statement. Do you think it make sense in general and
can be a possible direction of improvement for the current patch?
>
> 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.
Sure, they enable different optimisations. But, they enable highly
specialised optimisations. Having two GUCs looks too expensive.
Moreover, this stuff is cost-based and should work automatically. So, I
treat these GUCs as mostly debugging or last-chance stuff used to
disable features during severe slowdowns or bugs. It might make sense to
group them into a single 'Clause Reordering' parameter.
[1]
https://www.postgresql.org/message-id/flat/8742aaa8-9519-4a1f-91bd-364aec65f5cf%40gmail.com
--
regards, Andrei Lepikhov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-hackers@postgresql.org
Cc: lepihov@gmail.com, guofenglinux@gmail.com, dgrowleyml@gmail.com
Subject: Re: Reordering DISTINCT keys to match input path's pathkeys
In-Reply-To: <e56a0dbd-c969-4a69-b5c3-b640bc8ebc8a@gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox