Re: BUG #18652: Planner can not find pathkey item to sort for query with expression and expression index

From: Andrei Lepikhov <lepihov(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Richard Guo <guofenglinux(at)gmail(dot)com>, exclusion(at)gmail(dot)com, pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: BUG #18652: Planner can not find pathkey item to sort for query with expression and expression index
Date: 2024-10-12 06:05:25
Message-ID: 73d3a8bb-531d-4db3-be75-e9ba7001a3f3@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On 12/10/2024 03:59, Tom Lane wrote:
> Andrei Lepikhov <lepihov(at)gmail(dot)com> writes:
> But that's not what actually happens in the sole use of this code by
> prepare_sort_from_pathkeys. What will actually happen is that we
> will add the child EC member expression as a new member of the
> same tlist, so that the plan node's tlist will look like
>
> t2.i + 1, (t2.i + 1) + 0
I ended up with the same chain of events. During this scrutiny, I found
only a few sources of knowledge about why the code was written exactly
this way and what logic is under the hood. So, the current explanation
and discussion are profitable by themselves.

> I wonder whether we're doing more work here than we really need to.
> If the underlying table t1 has columns i and j, and we have an EC
> member that references t1.j while the tlist only mentions t1.i,
> wouldn't it still work to add t1.j to the tlist? So maybe groveling
> through the tlist members is unnecessary and we only need to be
> performing some kind of relation-level check on whether all the
> required relations are included in the input.
I'm not sure I understand this point. Do you mean something like
attached? I thought about that, but what if we have all the relations
under, but some columns (especially ones with no source relation) needed
are absent in the target list and used far below in the plan, or not
used at all?
The patch looks good.

--
regards, Andrei Lepikhov

Attachment Content-Type Size
variant.diff text/plain 2.0 KB

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Sandeep Thakkar 2024-10-12 15:06:42 Re: BUG #18646: The problem with the installer
Previous Message Richard Guo 2024-10-12 04:13:51 Re: BUG #18652: Planner can not find pathkey item to sort for query with expression and expression index