I wrote: > If multiple references are actually possible then this'd break it. There > seem to be no such cases in the regression tests though, and I'm having a > hard time wrapping my brain around what would cause it. "git blame" > traces this text to my own commit f44639e1b, which has the log entry > Don't crash if subquery appears multiple times in jointree. This should > not happen anyway, but let's try not to get completely confused if it does > (due to rewriter bugs or whatever). > so I'm thinking that this was only hypothetical.
Ah, found it. That was evidently a reaction to the immediately preceding commit (352871ac9), which fixed a rewriter bug that could lead to exactly the case of multiple jointree references to one RTE. I think this patch doesn't make things any worse for such a case though. If we re-introduced such a bug, the result would be an immediate null pointer crash while trying to process the second reference to a flattenable subquery. That's probably better for debuggability than what happens now, where we just silently process the duplicate reference. Anyway, I've stuck this into the next CF for future consideration. regards, tom lane PS: to save time for anyone else who wants to investigate this, it looks like the report mentioned in 352871ac9 was https://www.postgresql.org/message-id/007401c0860d%24bed809a0%241001a8c0%40archonet.com