El-Lotso <el(dot)lotso(at)gmail(dot)com> writes:
> I'm really at my wits end here.
Try to merge the multiple join keys into one, somehow. I'm not sure why
the planner is overestimating the selectivity of the combined join
conditions, but that's basically where your problem is coming from.
A truly brute-force solution would be "set enable_nestloop = off"
but this is likely to screw performance for other queries.
regards, tom lane