Re: group by will not use an index?

From: "Steinar H(dot) Gunderson" <sgunderson(at)bigfoot(dot)com>
To: pgsql-performance(at)postgresql(dot)org
Subject: Re: group by will not use an index?
Date: 2007-01-10 01:11:04
Message-ID: 20070110011104.GA21351@uio.no
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

On Tue, Jan 09, 2007 at 05:07:03PM -0800, Brian Herlihy wrote:
> Actually, as I recently discovered, GROUP BY is faster than DISTINCT. It's
> just due to how they are implemented, so don't go looking for any deep
> reason :) The thread "GROUP BY vs DISTINCT" from 2006-12-20 discusses it.
> DISTINCT sorts the results to find the unique rows, but GROUP BY uses a
> hash.

Actually, GROUP BY _can_ use a sort too, it's just that a hash is usually
faster.

/* Steinar */
--
Homepage: http://www.sesse.net/

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message Andrew Lazarus 2007-01-10 01:41:27 Re: group by will not use an index?
Previous Message Brian Herlihy 2007-01-10 01:07:03 Re: group by will not use an index?