Re: pgsql-server/ oc/src/sgml/runtime.sgml rc/back ...

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Christopher Kings-Lynne <chriskl(at)familyhealth(dot)com(dot)au>
Cc: pgsql-committers(at)postgresql(dot)org
Subject: Re: pgsql-server/ oc/src/sgml/runtime.sgml rc/back ...
Date: 2002-11-21 03:37:33
Message-ID: 6777.1037849853@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers pgsql-hackers

Christopher Kings-Lynne <chriskl(at)familyhealth(dot)com(dot)au> writes:
> Out of interest (since I was away while this was proposed I assume),
> what's the idea with hashed aggergation?

Old method: scan rows in order by the GROUP BY columns (requiring
a sort, or if you're lucky an indexscan), and execute one aggregation
at a time.

New method: scan rows in any old order (typically a seqscan), and run
all the per-group aggregates in parallel. It's a hash aggregation
because we use an in-memory hashtable indexed by the values of the GROUP
BY columns to keep track of the running state of each aggregate.

The hash method avoids a sort before aggregation, at the cost of a sort
afterwards if you want the results in non-random order. But the
post-sort is only sorting one row per group, which is usually a lot less
data than the input rows.

One case where the old method can still win is where you have
SELECT ... GROUP BY foo ORDER BY foo LIMIT n;
for small n. The hash method does not produce any output till it's
read all the input; the old method can produce a few rows very cheaply
if foo is indexed.

Also, of course, the hash method fails if you have too many groups to
permit the hashtable to fit in memory.

regards, tom lane

In response to

Browse pgsql-committers by date

  From Date Subject
Next Message Tom Lane 2002-11-21 04:40:26 pgsql-server/src/test/regress resultmap
Previous Message Bruce Momjian 2002-11-21 03:33:55 Re: [COMMITTERS] pgsql-server/ oc/src/sgml/runtime.sgml rc/back

Browse pgsql-hackers by date

  From Date Subject
Next Message Neil Conway 2002-11-21 03:44:06 Re: [GENERAL] Bug with sequence
Previous Message Bruce Momjian 2002-11-21 03:33:55 Re: [COMMITTERS] pgsql-server/ oc/src/sgml/runtime.sgml rc/back