I am not really sure if we should play with the planner code.
I suspect the real issue is that we’re assuming partitioned tables
always need a ctid, which wasn’t true before MERGE started using the
root ResultRelInfo. In fact, the old code already looked wrong -- it’s
been requiring a ctid even for partitioned tables where that was never
necessary. We can fix this by only requiring the junk ctid when we
actually operate through the root partitioned table, that is, for
MERGE. Like the attached.
With your patch, this issue didn't happen again.
But I still get a different output when I enable verbose in EXPLAIN,
Output: ctid (enable_partition_pruning = on)
vs
Output: NULL::oid(enable_partition_pruning = off)
From the user's perspective, it's a bit confusing.
I agree more with Tom’s opinion — we should throw an error like "cannot delete from foreign table p1"
But the plan only had a dummy root relation; CheckValidResultRel() doesn't work.
Some other code place may need to do something.
--