I gave this a quick spin and couldn't find any faults.
The bit about getting an incorrect hint when p_rel_visible is false had
me busy for a little while (specifically I ran into it with the
"unnamed_subquery" stuff added by commit bcedd8f5fce0), but maybe that's
a fringe enough case, as the comment in rte_visible_if_lateral says.
I did wonder why errorMissingColumn doesn't consider rte_visible_if_* in
the case when there *is* an rsecond candidate. I understand that the
reason is that if we come across any exact match we already return that
one without looking for a second one. Maybe this deserves a comment (in
errorMissingColumn I mean) but I also wonder if we shouldn't scan the
whole RT in case there's another exact match that's also not visible.
--
Álvaro Herrera Breisgau, Deutschland — https://www.EnterpriseDB.com/
"Learn about compilers. Then everything looks like either a compiler or
a database, and now you have two problems but one of them is fun."
https://twitter.com/thingskatedid/status/1456027786158776329