"Heikki Linnakangas" <heikki(at)enterprisedb(dot)com> writes:
> + root->parse->rtable = list_union(root->parse->rtable, subquery->rtable);
That's one heck of a scary patch: nowhere in list_union's API is there
any guarantee that it preserves list ordering, but we *must not* change
the positions of the existing rtable entries.
I think it might be better to fix the problem in
pull_up_union_leaf_queries instead; given that it wasn't broken till
recently, I think it's arguably that function's fault. Can we redesign
it to pull up everything in the subquery rtable, not just what was
referenced?
regards, tom lane