Re: BUG #18652: Planner can not find pathkey item to sort for query with expression and expression index - Mailing list pgsql-bugs

From Tom Lane
Subject Re: BUG #18652: Planner can not find pathkey item to sort for query with expression and expression index
Date
Msg-id 2572174.1728534842@sss.pgh.pa.us
Whole thread Raw
In response to Re: BUG #18652: Planner can not find pathkey item to sort for query with expression and expression index  (Richard Guo <guofenglinux@gmail.com>)
Responses Re: BUG #18652: Planner can not find pathkey item to sort for query with expression and expression index
List pgsql-bugs
Richard Guo <guofenglinux@gmail.com> writes:
> On Thu, Oct 10, 2024 at 5:43 AM Tom Lane <tgl@sss.pgh.pa.us> wrote:
>> It looks like we are generating a Path tree in which one of the
>> inputs to a MergeAppend is a plain unsorted seqscan, which'd
>> be all right except it doesn't expose the required sort value
>> in its targetlist.

> Correct.  In addition, find_computable_ec_member() fails to find a
> computable expression from its targetlist.
> ...
> I think this is because find_computable_ec_member() only tries to
> match Vars.  Maybe we should teach it to also match OpExprs?

Not sure.  Having nothing much better to do this evening,
I cranked up a VM with an old OS and was able to "git bisect"
the problem with some tedious manual hackery.  The end result was

11cad29c91524aac1d0b61e0ea0357398ab79bf8 is the first bad commit
commit 11cad29c91524aac1d0b61e0ea0357398ab79bf8
Author: Tom Lane <tgl@sss.pgh.pa.us>
Date:   Thu Oct 14 16:56:39 2010 -0400

    Support MergeAppend plans, to allow sorted output from append relations.

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.

            regards, tom lane



pgsql-bugs by date:

Previous
From: Andrei Lepikhov
Date:
Subject: Re: Reference to - BUG #18349: ERROR: invalid DSA memory alloc request size 1811939328, CONTEXT: parallel worker
Next
From: Andrei Lepikhov
Date:
Subject: Re: BUG #18652: Planner can not find pathkey item to sort for query with expression and expression index