Re: BUG #18652: Planner can not find pathkey item to sort for query with expression and expression index
Alena Rybakina <a.rybakina@postgrespro.ru>
From: Alena Rybakina <a.rybakina@postgrespro.ru>
To: Richard Guo <guofenglinux@gmail.com>
Cc: Tom Lane <tgl@sss.pgh.pa.us>, exclusion@gmail.com,
pgsql-bugs@lists.postgresql.org, Andrei Lepikhov <lepihov@gmail.com>
Date: 2024-10-11T08:02:31Z
Lists: pgsql-bugs
On 10.10.2024 14:57, Richard Guo wrote: > On Thu, Oct 10, 2024 at 12:34 PM Tom Lane <tgl@sss.pgh.pa.us> wrote: >> So it's specific to MergeAppend and it's been wrong from day zero. >> That makes me think it's probably not find_computable_ec_member's >> fault directly. Fixing it there might be the most expedient answer, >> but I feel like first we should drill down a bit further to understand >> the root problem. I'm too tired to do more tonight though. > Usually a relation's targetlist should include only Vars and PHVs > during this phase. I think this may be the rationale behind > find_computable_ec_member matching only Vars and quasi-Vars. However, > for a child rel, when we copy the parent's targetlist with appropriate > substitution, we may generate arbitrary expressions, such as an OpExpr > for 'i + 1' in this case. > > We have a note in the comments in set_append_rel_size saying that > > * Code that might be looking at an appendrel child must cope with > * such. > > It seems to me that find_computable_ec_member does not get this memo. > > Alternatively, can we wrap non-var expressions in a childrel's > targetlist into PHVs, so that we do not need special handling for an > appendrel child? I have not tried this though. > To be honest, looking at the MergeAppend processing plan, it’s not entirely clear to me what the functional difference is between set_rel_pathlist and find_computable_ec_member. Both prepare pathkeys , but what the first function doesn't do is what the other one needs to do?Could you explain it to me? -- Regards, Alena Rybakina Postgres Professional
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