Received: from localhost (maia-2.hub.org [200.46.204.187]) by postgresql.org (Postfix) with ESMTP id 20BB59F9F46 for ; Wed, 20 Dec 2006 07:00:27 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.187]) (amavisd-new, port 10024) with ESMTP id 60781-10 for ; Wed, 20 Dec 2006 07:00:16 -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 B3EFE9FA2BA for ; Wed, 20 Dec 2006 07:00:19 -0400 (AST) Received: from trofast.sesse.net ([129.241.93.32]) by cassarossa.samfundet.no with esmtp (Exim 4.50) id 1GwzBC-0006Rs-03; Wed, 20 Dec 2006 12:00:10 +0100 Received: from sesse by trofast.sesse.net with local (Exim 3.36 #1 (Debian)) id 1GwzB9-0008Kh-00; Wed, 20 Dec 2006 12:00:07 +0100 Date: Wed, 20 Dec 2006 12:00:07 +0100 From: "Steinar H. Gunderson" To: Brian Herlihy Cc: Postgresql Performance Subject: Re: GROUP BY vs DISTINCT Message-ID: <20061220105739.GB31739@uio.no> Mail-Followup-To: Brian Herlihy , Postgresql Performance References: <20061220071940.17382.qmail@web52303.mail.yahoo.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20061220071940.17382.qmail@web52303.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: 200612/486 X-Sequence-Number: 22542 On Tue, Dec 19, 2006 at 11:19:39PM -0800, Brian Herlihy wrote: > Actually, I think I answered my own question already. But I want to > confirm - Is the GROUP BY faster because it doesn't have to sort results, > whereas DISTINCT must produce sorted results? This wasn't clear to me from > the documentation. If it's true, then I could save considerable time by > using GROUP BY where I have been using DISTINCT in the past. Usually I > simply want a count of the distinct values, and there is no need to sort > for that. You are right; at the moment, GROUP BY is more intelligent than DISTINCT, even if they have to compare the same columns. This is, as always, something that could be improved in a future release, TTBOMK. /* Steinar */ -- Homepage: http://www.sesse.net/