Re: Avoid computing ORDER BY junk columns unnecessarily

From: Richard Guo <guofenglinux(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Heikki Linnakangas <hlinnaka(at)iki(dot)fi>, Xiaoran Wang <fanfuxiaoran(at)gmail(dot)com>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>, Andrew Kane <andrew(at)ankane(dot)org>, Matthias van de Meent <boekewurm+postgres(at)gmail(dot)com>
Subject: Re: Avoid computing ORDER BY junk columns unnecessarily
Date: 2023-12-25 11:21:42
Message-ID: CAMbWs48z9NqdwL6LnQZwnV8RR=BKEpXyDLoYaj5RzFOMvFheaw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Sat, Dec 23, 2023 at 1:32 AM Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:

> Heikki Linnakangas <hlinnaka(at)iki(dot)fi> writes:
> > On 22/12/2023 17:24, Tom Lane wrote:
> >> How much of your patchset still makes sense if we assume that we
> >> can always extract the ORDER BY column values from the index?
>
> > That would make it much less interesting. But I don't think that's a
> > good assumption. Especially in the kNN case, the ORDER BY value would
> > not be stored in the index. Most likely the index needs to calculate it
> > in some form, but it might take shortcuts like avoiding the sqrt().
>
> Yeah, fair point. I'll try to take a look at your patchset after
> the holidays.

Agreed.

I haven't looked into these patches, but it seems that there is an issue
with how the targetlist is handled for foreign rels. The following test
case for postgres_fdw hits the Assert in apply_tlist_labeling().

contrib_regression=# SELECT c3, c4 FROM ft1 ORDER BY c3, c1 LIMIT 1;
server closed the connection unexpectedly

When we create foreign final path in add_foreign_final_paths(), we use
root->upper_targets[UPPERREL_FINAL] as the PathTarget. This PathTarget
is set in grouping_planner(), without removing the junk columns. I
think this is why the above query hits the Assert.

Thanks
Richard

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Alexander Korotkov 2023-12-25 11:36:37 Re: Optimization outcome depends on the index order
Previous Message Junwang Zhao 2023-12-25 10:57:51 Re: Proposal to include --exclude-extension Flag in pg_dump