Oh, I have it: the right fix here is to leave the right subquery's
tlist entirely alone, and instead compute the extra columns in its
parent query. The reason we didn't see a problem for #19922 in
the lefthand subquery is that it's done that way for the lefthand
subquery; but for some reason we didn't do it like that for the
righthand one.
Now that I look more closely, I think that the SQL spec's rewrite
rule actually directs us to do it like that. So there's no
semantic hazard in the spec, only in our implementation.
regards, tom lane