pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Christopher Kings-Lynne <chriskl@familyhealth.com.au>
To: Max Baker <max@warped.org>
To: PostgreSQL Performance Mailing List <pgsql-performance@postgresql.org>
Subject: Re: speeding up COUNT and DISTINCT queries
Date: Thu, 13 Mar 2003 10:20:04 +0800
Message-ID: <099c01c2e907$0ede0770$6500a8c0@fhp.internal> (raw)
References: <20030312223811.GM30411@warped.org>

Try setting up a trigger to maintain a separate table containing only the
distinct values...

Chris

----- Original Message -----
From: "Max Baker" <max@warped.org>
To: "PostgreSQL Performance Mailing List" <pgsql-performance@postgresql.org>
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
>




view thread (14+ messages)  latest in thread

Message-ID: <099c01c2e907$0ede0770$6500a8c0@fhp.internal>
Permalink:  ../099c01c2e907$0ede0770$6500a8c0@fhp.internal/
Also on:    postgresql.org/message-id/099c01c2e907$0ede0770$6500a8c0@fhp.internal

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-performance@postgresql.org
  Cc: chriskl@familyhealth.com.au, max@warped.org
  Subject: Re: speeding up COUNT and DISTINCT queries
  In-Reply-To: <099c01c2e907$0ede0770$6500a8c0@fhp.internal>
  References: <20030312223811.GM30411@warped.org> <099c01c2e907$0ede0770$6500a8c0@fhp.internal>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox