Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 395E34769F9 for ; Fri, 4 Oct 2002 11:27:47 -0400 (EDT) Received: from wolff.to (wolff.to [66.93.197.35]) by postgresql.org (Postfix) with SMTP id B81784771E9 for ; Fri, 4 Oct 2002 11:22:34 -0400 (EDT) Received: (qmail 14427 invoked by uid 500); 4 Oct 2002 15:31:08 -0000 Date: Fri, 4 Oct 2002 10:31:08 -0500 From: Bruno Wolff III To: Michael Contzen Cc: pgsql-sql@postgresql.org Subject: Re: How slow is distinct - 2nd Message-ID: <20021004153108.GA14180@wolff.to> Mail-Followup-To: Michael Contzen , pgsql-sql@postgresql.org References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.3.25i X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200210/65 X-Sequence-Number: 9783 On Tue, Oct 01, 2002 at 14:18:50 +0200, Michael Contzen wrote: > Here the table: > > mc=# \d egal > Table "public.egal" > Column | Type | Modifiers > --------+---------+----------- > i | integer | > > mc=# select count(*) from egal; > count > --------- > 7227744 > (1 row) > > mc=# select count(distinct i) from egal; > count > ------- > 67 > (1 row) This suggests that the best way to do this is with a hash instead of a sort. If you have lots of memory you might try increasing the sort memory size.