Re: BUG #18652: Planner can not find pathkey item to sort for query with expression and expression index
Andrei Lepikhov <lepihov@gmail.com>
From: Andrei Lepikhov <lepihov@gmail.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Richard Guo <guofenglinux@gmail.com>, exclusion@gmail.com,
pgsql-bugs@lists.postgresql.org
Date: 2024-10-12T06:05:25Z
Lists: pgsql-bugs
Attachments
- variant.diff (text/plain) patch
On 12/10/2024 03:59, Tom Lane wrote: > Andrei Lepikhov <lepihov@gmail.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
Commits
-
Correctly identify which EC members are computable at a plan node.
- 9f954177b1eb 18.0 landed
- 76de4b182cad 13.17 landed
- 64635c8af92d 16.5 landed
- 54889ea64baa 17.1 landed
- 4f3bccbaaeb4 15.9 landed
- 4ca708eb3588 14.14 landed
-
Support MergeAppend plans, to allow sorted output from append relations.
- 11cad29c9152 9.1.0 cited