Hi,
On 2025-05-18 19:31:33 -0400, Tom Lane wrote:
> While chasing down Valgrind leakage reports, I was disturbed
> to realize that some of them arise from a case where the
> executor scribbles on the plan tree it's given, which it is
> absolutely not supposed to do:
>
> /*
> * Initialize result tuple slot and assign its rowtype using the first
> * RETURNING list. We assume the rest will look the same.
> */
> mtstate->ps.plan->targetlist = (List *) linitial(returningLists);
>
> A bit of git archaeology fingers Andres' commit 4717fdb14, which we
> can't easily revert since he later got rid of ExecAssignResultType
> altogether. But I think we need to do something about it --- it's
> purest luck that this doesn't cause serious problems in some cases.
I have no idea what I was smoking at that time, this clearly is wrong.
I think the reason it doesn't cause problems is that we're just using the
first child's targetlist every time and we're just assigning the same value
back every time.
What's even more absurd is: Why do we even need to assign the result type at
all? Before & after 4717fdb14. The planner ought to have already figured this
out, no?
It seems that if not, we'd have a problem anyway, who says the "calling" nodes
(say a wCTE) can cope with whatever output we come up with?
Except of course, there is exactly one case in our tests where the tupledescs
aren't equal :(
I've not dug fully into this, but I thought I should send this email to
confirm that I'm looking into the issue.
Greetings,
Andres Freund