"Rainer Mager" <rmager@vgkk.com> writes:
> First, this type of query seems to use exponential amounts of memory.
Hmm. What does EXPLAIN show as the plan for the query? How long does
it take to do the EXPLAIN? If the EXPLAIN alone takes a lot of time/
space, then you need to reduce the size of the planner's search space
with an explicit JOIN --- see
http://www.ca.postgresql.org/users-lounge/docs/7.1/postgres/explicit-joins.html
regards, tom lane