Skip site navigation (1) Skip section navigation (2)

Re: speeding up COUNT and DISTINCT queries

From: "Chad Thompson" <chad(at)weblinkservices(dot)com>
To: "Max Baker" <max(at)warped(dot)org>,"PostgreSQL Performance Mailing List" <pgsql-performance(at)postgresql(dot)org>
Subject: Re: speeding up COUNT and DISTINCT queries
Date: 2003-03-12 22:55:09
Message-ID: 0ca601c2e8ea$6f7783d0$32021aac@chad (view raw or flat)
Thread:
Lists: pgsql-performance
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" <max(at)warped(dot)org>
To: "PostgreSQL Performance Mailing List" <pgsql-performance(at)postgresql(dot)org>
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(at)postgresql(dot)org so that your
> message can get through to the mailing list cleanly
>


In response to

Responses

pgsql-performance by date

Next:From: Jean-Luc LachanceDate: 2003-03-12 23:40:36
Subject: Re: speeding up COUNT and DISTINCT queries
Previous:From: Rod TaylorDate: 2003-03-12 22:52:19
Subject: Re: speeding up COUNT and DISTINCT queries

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group