pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Slow SELECT with distinct, in a TIMESTAMP type column
4+ messages / 2 participants
[nested] [flat]

* Slow SELECT with distinct, in a TIMESTAMP type column
@ 2002-06-24 13:58 Marcos Garcia <marcos-p-garcia@ptinovacao.pt>
  2002-06-24 18:36 ` Re: Slow SELECT with distinct, in a TIMESTAMP type column Stephan Szabo <sszabo@megazone23.bigpanda.com>
  0 siblings, 1 reply; 4+ messages in thread

From: Marcos Garcia @ 2002-06-24 13:58 UTC (permalink / raw)
  To: pgsql-sql

Hi,


I've a table "send_total" like this:

                                      Table "send_total"
  Column   |           Type           |                      
Modifiers                       
-----------+--------------------------+-------------------------------------------------------
 id        | integer                  | not null default
nextval('"send_total_id_seq"'::text)
 smsdate   | timestamp with time zone | 
 idclient  | integer                  | not null
 recv      | integer                  | default 0
 send      | integer                  | default 0
 recv_conf | integer                  | default 0
 send_conf | integer                  | default 0
 conf0     | integer                  | default 0
 conf1     | integer                  | default 0
 conf2     | integer                  | default 0
 conf3     | integer                  | default 0
 conf4     | integer                  | default 0
 conf5     | integer                  | default 0
 conf6     | integer                  | default 0
 conf7     | integer                  | default 0
Indexes: send_total_idclient_idx,
         send_total_smsdate_idx
Primary key: send_total_pkey
Unique keys: send_total_idclismsdate
(idclient and smsdate must be unique)


The problem is that my query is too slow when i use distinct:

pgsql> explain analyze SELECT distinct(smsdate) FROM send_total;

NOTICE:  QUERY PLAN:

Unique  (cost=15840.31..15870.81 rows=1220 width=8) (actual
time=56358.93..56452.78 rows=6670 loops=1)
  ->  Sort  (cost=15840.31..15840.31 rows=12203 width=8) (actual
time=56358.91..56436.95 rows=12062 loops=1)
        ->  Seq Scan on send_total  (cost=0.00..15012.03 rows=12203
width=8) (actual time=0.55..56205.25 rows=12062 loops=1)
Total runtime: 56518.26 msec


This query is becoming slower and slower, day by day.
What i have to do to optimize my query or database??? I've this database
working since January 2002.

I've tried to make the following command, but without success:

$ /usr/bin/vacuumdb -z -d dbname -t send_total



Thanks in advance,


M.P.Garcia





-- 
M.P.Garcia
PT Inovação, SA
Serviços e Redes Móveis 
Rua José Ferreira Pinto Basto - 3810 Aveiro
Tel: 234 403 253  -  Fax: 234 424 160
E-mail: marcos-p-garcia@ptinovacao.pt

Attachments:

  signature.asc (application/pgp-signature, 231B) download

^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: Slow SELECT with distinct, in a TIMESTAMP type column
  2002-06-24 13:58 Slow SELECT with distinct, in a TIMESTAMP type column Marcos Garcia <marcos-p-garcia@ptinovacao.pt>
@ 2002-06-24 18:36 ` Stephan Szabo <sszabo@megazone23.bigpanda.com>
  2002-06-24 19:46   ` Re: Slow SELECT with distinct, in a TIMESTAMP type column Marcos Garcia <marcos-p-garcia@ptinovacao.pt>
  0 siblings, 1 reply; 4+ messages in thread

From: Stephan Szabo @ 2002-06-24 18:36 UTC (permalink / raw)
  To: Marcos Garcia <marcos-p-garcia@ptinovacao.pt>; +Cc: pgsql-sql


On 24 Jun 2002, Marcos Garcia wrote:

> The problem is that my query is too slow when i use distinct:
>
> pgsql> explain analyze SELECT distinct(smsdate) FROM send_total;
>
> NOTICE:  QUERY PLAN:
>
> Unique  (cost=15840.31..15870.81 rows=1220 width=8) (actual
> time=56358.93..56452.78 rows=6670 loops=1)
>   ->  Sort  (cost=15840.31..15840.31 rows=12203 width=8) (actual
> time=56358.91..56436.95 rows=12062 loops=1)
>         ->  Seq Scan on send_total  (cost=0.00..15012.03 rows=12203
> width=8) (actual time=0.55..56205.25 rows=12062 loops=1)
> Total runtime: 56518.26 msec

As a question, what does explain analyze show if you
set enable_seqscan=off; first?







^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: Slow SELECT with distinct, in a TIMESTAMP type column
  2002-06-24 13:58 Slow SELECT with distinct, in a TIMESTAMP type column Marcos Garcia <marcos-p-garcia@ptinovacao.pt>
  2002-06-24 18:36 ` Re: Slow SELECT with distinct, in a TIMESTAMP type column Stephan Szabo <sszabo@megazone23.bigpanda.com>
@ 2002-06-24 19:46   ` Marcos Garcia <marcos-p-garcia@ptinovacao.pt>
  2002-06-24 21:06     ` Re: Slow SELECT with distinct, in a TIMESTAMP type column Stephan Szabo <sszabo@megazone23.bigpanda.com>
  0 siblings, 1 reply; 4+ messages in thread

From: Marcos Garcia @ 2002-06-24 19:46 UTC (permalink / raw)
  To: Stephan Szabo <sszabo@megazone23.bigpanda.com>; +Cc: pgsql-sql


When i make the set enable_seqscan = off the result is:

dbname=# set enable_seqscan = off;
SET VARIABLE
dbname=# explain analyze SELECT distinct(smsdate) FROM send_total;

NOTICE:  QUERY PLAN:

Unique  (cost=0.00..31084.39 rows=1232 width=8) (actual
time=108.60..195210.91 rows=6676 loops=1)
  ->  Index Scan using send_total_smsdate_idx on send_total 
(cost=0.00..31053.60 rows=12315 width=8) (actual time=108.59..195145.43
rows=12087 loops=1)
Total runtime: 195226.24 msec




On Mon, 2002-06-24 at 19:36, Stephan Szabo wrote:
> 
> On 24 Jun 2002, Marcos Garcia wrote:
> 
> > The problem is that my query is too slow when i use distinct:
> >
> > pgsql> explain analyze SELECT distinct(smsdate) FROM send_total;
> >
> > NOTICE:  QUERY PLAN:
> >
> > Unique  (cost=15840.31..15870.81 rows=1220 width=8) (actual
> > time=56358.93..56452.78 rows=6670 loops=1)
> >   ->  Sort  (cost=15840.31..15840.31 rows=12203 width=8) (actual
> > time=56358.91..56436.95 rows=12062 loops=1)
> >         ->  Seq Scan on send_total  (cost=0.00..15012.03 rows=12203
> > width=8) (actual time=0.55..56205.25 rows=12062 loops=1)
> > Total runtime: 56518.26 msec
> 
> As a question, what does explain analyze show if you
> set enable_seqscan=off; first?
> 
-- 
M.P.Garcia
PT Inovação, SA
Serviços e Redes Móveis 
Rua José Ferreira Pinto Basto - 3810 Aveiro
Tel: 234 403 253  -  Fax: 234 424 160
E-mail: marcos-p-garcia@ptinovacao.pt

Attachments:

  signature.asc (application/pgp-signature, 231B) download

^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: Slow SELECT with distinct, in a TIMESTAMP type column
  2002-06-24 13:58 Slow SELECT with distinct, in a TIMESTAMP type column Marcos Garcia <marcos-p-garcia@ptinovacao.pt>
  2002-06-24 18:36 ` Re: Slow SELECT with distinct, in a TIMESTAMP type column Stephan Szabo <sszabo@megazone23.bigpanda.com>
  2002-06-24 19:46   ` Re: Slow SELECT with distinct, in a TIMESTAMP type column Marcos Garcia <marcos-p-garcia@ptinovacao.pt>
@ 2002-06-24 21:06     ` Stephan Szabo <sszabo@megazone23.bigpanda.com>
  0 siblings, 0 replies; 4+ messages in thread

From: Stephan Szabo @ 2002-06-24 21:06 UTC (permalink / raw)
  To: Marcos Garcia <marcos-p-garcia@ptinovacao.pt>; +Cc: pgsql-sql

On 24 Jun 2002, Marcos Garcia wrote:

>
> When i make the set enable_seqscan = off the result is:
>
> dbname=# set enable_seqscan = off;
> SET VARIABLE
> dbname=# explain analyze SELECT distinct(smsdate) FROM send_total;
>
> NOTICE:  QUERY PLAN:
>
> Unique  (cost=0.00..31084.39 rows=1232 width=8) (actual
> time=108.60..195210.91 rows=6676 loops=1)
>   ->  Index Scan using send_total_smsdate_idx on send_total
> (cost=0.00..31053.60 rows=12315 width=8) (actual time=108.59..195145.43
> rows=12087 loops=1)
> Total runtime: 195226.24 msec

Well the plan choice makes sense (since it's about 3.5x faster as
a sequence scan over the index scan).
It looks like most of the time is taken up by the actual scan (is
"select smsdate from send_total" pretty much as slow?).






^ permalink  raw  reply  [nested|flat] 4+ messages in thread


end of thread, other threads:[~2002-06-24 21:06 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2002-06-24 13:58 Slow SELECT with distinct, in a TIMESTAMP type column Marcos Garcia <marcos-p-garcia@ptinovacao.pt>
2002-06-24 18:36 ` Stephan Szabo <sszabo@megazone23.bigpanda.com>
2002-06-24 19:46   ` Marcos Garcia <marcos-p-garcia@ptinovacao.pt>
2002-06-24 21:06     ` Stephan Szabo <sszabo@megazone23.bigpanda.com>

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