I wrote: > ... I also > don't like the undocumented way that you've got build_base_rel_tlists > working on something that's not the final tlist, and then going back > and doing more work of the same sort later. I wonder whether we can > postpone build_base_rel_tlists until after the other stuff happens, > so that it can continue to do all of the tlist-distribution work.
On further reflection: we don't really need the full build_base_rel_tlists pushups for these extra variables. The existence of the original rowmark variable will be sufficient, for example, to make sure that we don't decide the parent partitioned table can be thrown away as a useless join. All we need to do is add the new Var to the parent's reltarget and adjust its attr_needed, and we can do that very late in query_planner. So now I'm thinking leave build_base_rel_tlists() where it is, and then fix up the tlist/reltarget data on the fly when we discover that new child rels need more rowmark types than we had before. (This'd be another reason to keep the tlist in root->processed_tlist throughout, likely.) regards, tom lane