Re: queries with lots of UNIONed relations - Mailing list pgsql-performance

From Tom Lane
Subject Re: queries with lots of UNIONed relations
Date
Msg-id 20541.1294963827@sss.pgh.pa.us
Whole thread Raw
In response to Re: queries with lots of UNIONed relations  (Jon Nelson <jnelson+pgsql@jamponi.net>)
Responses Re: queries with lots of UNIONed relations
List pgsql-performance
Jon Nelson <jnelson+pgsql@jamponi.net> writes:
> On Thu, Jan 13, 2011 at 5:05 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
>> If you have enough memory to de-dup them individually, you surely have
>> enough to de-dup all at once.

> If everything were available up-front, sure.
> However, and please correct me if I'm wrong, but doesn't postgresql
> work in a fairly linear fashion, moving from table to table performing
> a series of operations on each?

Doing a single sort+uniq works like that.  But the alternate plan you
are proposing we should consider involves building all the lower
hashtables, and then reading from them to fill the upper hashtable.
Max memory consumption *is* worst case here.  Remember HashAggregate
is incapable of swapping to disk (and if it did, you wouldn't be nearly
as pleased with its performance).

            regards, tom lane

pgsql-performance by date:

Previous
From: Jon Nelson
Date:
Subject: Re: queries with lots of UNIONed relations
Next
From: Mladen Gogala
Date:
Subject: Re: queries with lots of UNIONed relations