X-Original-To: pgsql-performance@postgresql.org Received: from houston.familyhealth.com.au (unknown [203.59.48.253]) by postgresql.org (Postfix) with ESMTP id CFAA14758E6 for ; Wed, 12 Mar 2003 21:19:52 -0500 (EST) Received: (from root@localhost) by houston.familyhealth.com.au (8.11.6/8.11.6) id h2D2JtX01227 for pgsql-performance@postgresql.org; Thu, 13 Mar 2003 10:19:55 +0800 (WST) (envelope-from chriskl@familyhealth.com.au) Received: from mariner (mariner.internal [192.168.0.101]) by houston.familyhealth.com.au (8.11.6/8.9.3) with SMTP id h2D2Jo701134; Thu, 13 Mar 2003 10:19:50 +0800 (WST) Message-ID: <099c01c2e907$0ede0770$6500a8c0@fhp.internal> From: "Christopher Kings-Lynne" To: "Max Baker" , "PostgreSQL Performance Mailing List" References: <20030312223811.GM30411@warped.org> Subject: Re: speeding up COUNT and DISTINCT queries Date: Thu, 13 Mar 2003 10:20:04 +0800 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.2800.1106 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106 X-scanner: scanned by Inflex 0.1.5c - (http://www.inflex.co.za/) X-Archive-Number: 200303/93 X-Sequence-Number: 1391 Try setting up a trigger to maintain a separate table containing only the distinct values... Chris ----- Original Message ----- From: "Max Baker" To: "PostgreSQL Performance Mailing List" Sent: Thursday, March 13, 2003 6:38 AM 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 >