Martin Hampl <Martin(dot)Hampl(at)gmx(dot)de> writes:
> It would be very nice, if someone could have a look at the query I'm
> trying to optimize. At the moment, I don't understand PostgreSQL's
> behaviour and are stuck. Thanks a lot in advance.
Did you ANALYZE these tables? Also, please post EXPLAIN ANALYZE not
just EXPLAIN when complaining about bad plans. Since the essence of
your complaint is that the planner's estimates are wrong, showing us
only estimates and not reality makes it hard to give constructive
suggestions ...
regards, tom lane