I didn't see the query itself in the message, but it looks to me like
it's poorly formed. Could you send it?
By quick glance, either you're using a bunch of explicit joins that are
poorly formed (you've made a bad choice in order) or those particular
IDs are really popular. There are a number of sequential scans that
possibly should be index scans.
> EXPLAIN ANALYZE RESULTS:
> Limit (cost=370518.31..370518.31 rows=1 width=540) (actual time=1168722.18..1168722.20 rows=5 loops=1)
> -> Sort (cost=370518.31..370518.31 rows=1 width=540) (actual time=1168722.18..1168722.18 rows=5 loops=1)
> Sort Key: b.batchdate
--
Rod Taylor <rbt@rbt.ca>
PGP Key: http://www.rbt.ca/rbtpub.asc