I can add that setting enable_nestloop = 0 cuts the runtime for this query down to about 4 seconds.Disabling nested loops globaly does however impacts performance of a lot of other queries.
/ Eskil