Received: from localhost (maia-5.hub.org [200.46.204.182]) by postgresql.org (Postfix) with ESMTP id 183229FA2C4 for ; Tue, 9 Jan 2007 21:10:14 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.182]) (amavisd-new, port 10024) with ESMTP id 80264-05 for ; Tue, 9 Jan 2007 21:10:01 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from cassarossa.samfundet.no (cassarossa.samfundet.no [129.241.93.19]) by postgresql.org (Postfix) with ESMTP id 26B099FB1CC for ; Tue, 9 Jan 2007 21:10:05 -0400 (AST) Received: from trofast.sesse.net ([129.241.93.32]) by cassarossa.samfundet.no with esmtp (Exim 4.50) id 1H4Ryd-0007Ic-0a for pgsql-performance@postgresql.org; Wed, 10 Jan 2007 02:10:03 +0100 Received: from sesse by trofast.sesse.net with local (Exim 3.36 #1 (Debian)) id 1H4Rzc-0005ZA-00 for ; Wed, 10 Jan 2007 02:11:04 +0100 Date: Wed, 10 Jan 2007 02:11:04 +0100 From: "Steinar H. Gunderson" To: pgsql-performance@postgresql.org Subject: Re: group by will not use an index? Message-ID: <20070110011104.GA21351@uio.no> Mail-Followup-To: pgsql-performance@postgresql.org References: <20070110010703.7815.qmail@web52315.mail.yahoo.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20070110010703.7815.qmail@web52315.mail.yahoo.com> X-Operating-System: Linux 2.6.19 on a x86_64 X-Message-Flag: Outlook? --> http://www.mozilla.org/products/thunderbird/ User-Agent: Mutt/1.5.13 (2006-08-11) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200701/126 X-Sequence-Number: 22727 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/