Here's said patch. Although this fixes the described problem and passes check-world, I'm not totally happy with it yet: it feels like the new add_outer_joins_to_relids() function is too expensive to be doing every time we construct a join relation.
Do we need to revise how we build target list for outer join by adjusting the nullingrels of Vars and PHVs from input_rel in a similar way?
After more thought on this idea I think it's more promising, as long as we do proper adjustments to outer join's target list. AFAICS we need to do two things for the adjustment.
* we need to check whether the outer join has been completely performed before we add its relid to the nulling bitmap. For example, the pushed down B/C join should not mark C Vars as nulled by itself. This can be done by bms_is_member(sjinfo->ojrelid, joinrel->relids).
* for all the pushed down outer joins that have been completely performed just by now, we need to add their relids to the nulling bitmap if they can null the Var or PHV. For example, when we form the pulled up A/B join, we need to mark C Vars as nulled by the pushed down B/C join. To do this, I'm considering we can collect all the pushed down outer joins in add_outer_joins_to_relids().
Attached is the patch to do adjustments to outer join's target list. Note that it needs to be applied on the base of patch 'postpone-adding-pushed-down-ojrelid-to-relids.patch'.