Slow SELECT with distinct, in a TIMESTAMP type column

Поиск
Список
Период
Сортировка
От Marcos Garcia
Тема Slow SELECT with distinct, in a TIMESTAMP type column
Дата
Msg-id 1024927121.1062.297.camel@sargao
обсуждение исходный текст
Ответы Re: Slow SELECT with distinct, in a TIMESTAMP type column  (Stephan Szabo <sszabo@megazone23.bigpanda.com>)
Список 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
nullrecv     | integer                  | default 0send      | integer                  | default 0recv_conf | integer
               | default 0send_conf | integer                  | default 0conf0     | integer                  |
default0conf1     | integer                  | default 0conf2     | integer                  | default 0conf3     |
integer                 | default 0conf4     | integer                  | default 0conf5     | integer
|default 0conf6     | integer                  | default 0conf7     | 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

В списке pgsql-sql по дате отправления:

Предыдущее
От: "Oleg Lebedev"
Дата:
Сообщение: index problem
Следующее
От: Tom Lane
Дата:
Сообщение: Re: variance aggregate function incorrect? Reference Materials reg create aggregate