Re: MergeAppend could consider sorting cheapest child path

From: Richard Guo <guofenglinux(at)gmail(dot)com>
To: Alexander Korotkov <aekorotkov(at)gmail(dot)com>
Cc: Andrei Lepikhov <lepihov(at)gmail(dot)com>, Alexander Pyhalov <a(dot)pyhalov(at)postgrespro(dot)ru>, Andy Fan <zhihuifan1213(at)163(dot)com>, Bruce Momjian <bruce(at)momjian(dot)us>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Nikita Malakhov <HukuToc(at)gmail(dot)com>
Subject: Re: MergeAppend could consider sorting cheapest child path
Date: 2025-09-02 01:27:56
Message-ID: CAMbWs48FxC5qsTif9F4E_FcmyAeNx9_N6RpV2YuGKPN0a5wnog@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Tue, Sep 2, 2025 at 5:26 AM Alexander Korotkov <aekorotkov(at)gmail(dot)com> wrote:
> I have another idea. What if we allow MergeAppend paths only when at
> least one subpath is preordered. This trick also allow us to exclude
> MergeAppend(Sort) dominating Sort(Append). I see the regression tests
> changes now have much less volume and looks more reasonable. What do
> you think?

I skimmed through the test case changes, and I'm not sure all of them
are actual improvements. For example:

-> Append
- -> Foreign Scan on ftprt1_p1 t1_1
+ -> Sort
+ Sort Key: t1_1.a
+ -> Foreign Scan on ftprt1_p1 t1_1
-> Foreign Scan on ftprt1_p2 t1_2

It seems that this patch moves the sort operation for ftprt1_p1 from
the remote server to local. I'm not sure if this is an improvement,
or why it applies only to ftprt1_p1 and not to ftprt1_p2 (they have
very similar statistics).

Besides, I noticed that some plans have changed from an "Index Scan
with Index Cond" to a "Seq Scan with Filter + Sort". I'm also not
sure whether this change results in better performance.

- Richard

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Chao Li 2025-09-02 02:43:58 Re: SQL:2023 JSON simplified accessor support
Previous Message Julien Rouhaud 2025-09-02 00:03:04 Re: Extension security improvement: Add support for extensions with an owned schema