I wrote:
> "David G. Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com> writes:
>> My first impression is that this is a bug. Especially since the query
>> apparently executes in both left-join and right-join modes.
> Well, it's a longstanding deficiency anyway.
> ...
> Still, it is annoying. I wonder if there's a way to do it without
> either a large amount of new code or exponential time spent
> trying useless subexpression matches...
I've posted a draft fix for that at
https://www.postgresql.org/message-id/flat/531183.1772058731%40sss.pgh.pa.us
regards, tom lane