Currently the outer_plan used in postgresGetForeignPlan() can only be 'Join' or 'Sort + Join'. I'm wondering whether we can take this knowledge into consideration when we fix the outer_plan's tlist, to also fix the Join's tlist if it is below the Sort node.
Alternatively, how about we include in the EPQ path's pathtarget the
columns required for evaluating the local conditions when we consider EPQ paths with pathkeys? Something like attached.