X-Original-To: pgsql-performance@postgresql.org Received: from utahisp.com (utahisp.com [66.239.12.3]) by postgresql.org (Postfix) with ESMTP id E3123476347 for ; Wed, 12 Mar 2003 17:55:05 -0500 (EST) Received: from chad [63.230.8.76] by utahisp.com (SMTPD32-7.14) id AA513C0284; Wed, 12 Mar 2003 15:53:05 -0700 Message-ID: <0ca601c2e8ea$6f7783d0$32021aac@chad> From: "Chad Thompson" To: "Max Baker" , "PostgreSQL Performance Mailing List" References: <20030312223811.GM30411@warped.org> Subject: Re: speeding up COUNT and DISTINCT queries Date: Wed, 12 Mar 2003 15:55:09 -0700 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2720.3000 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 X-Declude-Sender: chad@weblinkservices.com [63.230.8.76] X-Note: This E-mail was scanned by Declude JunkMail (www.declude.com) for spam. X-Archive-Number: 200303/86 X-Sequence-Number: 1384 Ive found that group by works faster than distinct. Try EXPLAIN ANALYZE select mac from node group by mac; HTH Chad ----- Original Message ----- From: "Max Baker" To: "PostgreSQL Performance Mailing List" Sent: Wednesday, March 12, 2003 3:38 PM Subject: [PERFORM] speeding up COUNT and DISTINCT queries > I'm looking for a general method to > speed up DISTINCT and COUNT queries. > > > mydatabase=> EXPLAIN ANALYZE select distinct(mac) from node; > NOTICE: QUERY PLAN: > > Unique (cost=110425.67..110514.57 rows=3556 width=6) (actual > time=45289.78..45598.62 rows=25334 loops=1) > -> Sort (cost=110425.67..110425.67 rows=35561 width=6) (actual > time=45289.77..45411.53 rows=34597 loops=1) > -> Seq Scan on node (cost=0.00..107737.61 rows=35561 > width=6) (actual time=6.73..44383.57 rows=34597 loops=1) > > Total runtime: 45673.19 msec > ouch. > > I run VACCUUM ANALYZE once a day. > > Thanks, > max > > ---------------------------(end of broadcast)--------------------------- > TIP 3: if posting/reading through Usenet, please send an appropriate > subscribe-nomail command to majordomo@postgresql.org so that your > message can get through to the mailing list cleanly >