David Rowley <david.row...@2ndquadrant.com> writes: > On Thu, 3 Jan 2019 at 08:01, Tomas Vondra <tomas.von...@2ndquadrant.com> > wrote: >> AFAICS the patch essentially does two things: (a) identifies Append >> paths with a single member and (b) ensures the Vars are properly mapped >> when the Append node is skipped when creating the plan. >> I agree doing (a) in setrefs.c is too late, as mentioned earlier. But >> perhaps we could do at least (b) to setrefs.c?
> The problem I found with doing var translations in setrefs.c was that > the plan tree is traversed there breadth-first and in createplan.c we > build the plan depth-first. The problem I didn't manage to overcome > with that is that when we replace a "ProxyPath" (actually an Append > path marked as is_proxy=true) it only alter targetlists, etc of nodes > above that in the plan tree. The nodes below it and their targetlists > don't care, as these don't fetch Vars from nodes above them. If we do > the Var translation in setrefs then we've not yet looked at the nodes > that don't care and we've already done the nodes that do care. So the > tree traversal is backwards. I don't quite buy this argument, because you haven't given a reason why it doesn't apply with equal force to setrefs.c's elimination of no-op SubqueryScan nodes. Yet that does work. Stepping back for a minute: even if we get this to work, how often is it going to do anything useful? It seems like most of the other development that's going on is trying to postpone pruning till later, so I wonder how often we'll really know at the beginning of planning that only one child will survive. regards, tom lane