pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Miroslav Šulc <miroslav.sulc@startnet.cz>
To: pgsql-sql@postgresql.org
Subject: SELECT DISTINCT too slow
Date: Thu, 01 Jun 2006 15:26:09 +0200
Message-ID: <447EEAF1.7040305@startnet.cz> (raw)

Hello,

I have a table with cca 400,000 rows. The table contains column "key" of
varchar(20) type containing 10 distinct values. I want to get out what
distinct values are present in the column. I use this simple query,
which is very slow:

SELECT DISTINCT Key FROM MRTPContactValue

Here is the query plan:

QUERY PLAN

Unique  (cost=64882.26..66964.59 rows=9 width=9) (actual time=26139.972..29593.164 rows=10 loops=1)

  ->  Sort  (cost=64882.26..65923.43 rows=416466 width=9) (actual time=26139.964..27975.944 rows=416466 loops=1)

        Sort Key: "key"

        ->  Seq Scan on mrtpcontactvalue  (cost=0.00..8669.66 rows=416466 width=9) (actual time=0.026..2460.535 rows=416466 loops=1)

Total runtime: 29603.159 ms


I've tried index on the "key" column but no improvement.

Is there a way to speed the SELECT up?

Thank you for any suggestions.

-- 
Miroslav Šulc

Attachments:

miroslav.sulc.vcf (text/x-vcard, 347B) download begin:vcard fn;quoted-printable:Miroslav =C5=A0ulc n;quoted-printable:=C5=A0ulc;Miroslav org:StartNet s.r.o. adr;quoted-printable;quoted-printable:;;Schodov=C3=A1 309/10;Praha 5;;150 00;=C4=8Cesk=C3=A1 republika email;internet:miroslav.sulc@startnet.cz tel;cell:+420 603 711 413 x-mozilla-html:TRUE url:http://www.startnet.cz version:2.1 end:vcard

view thread (13+ messages)  latest in thread

Message-ID: <447EEAF1.7040305@startnet.cz>
Permalink:  ../447EEAF1.7040305@startnet.cz/
Also on:    postgresql.org/message-id/447EEAF1.7040305@startnet.cz

 · 

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 using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: miroslav.sulc@startnet.cz
  Subject: Re: SELECT DISTINCT too slow
  In-Reply-To: <447EEAF1.7040305@startnet.cz>

* 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