pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Alvaro Herrera <alvherre@commandprompt.com>
To: Miroslav ?ulc <miroslav.sulc@startnet.cz>
Cc: pgsql-sql@postgresql.org
Subject: Re: SELECT DISTINCT too slow
Date: Thu, 1 Jun 2006 09:53:10 -0400
Message-ID: <20060601135310.GB18513@surnet.cl> (raw)
In-Reply-To: <447EEAF1.7040305@startnet.cz>
References: <447EEAF1.7040305@startnet.cz>

Miroslav ?ulc wrote:
> 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

You could get the universe of values from the table where this is a
primary key, and use an IN clause (which apparently is more efficient
than an EXISTS in some cases, but try that too) to search for values
that exist in the MRTPContactValue table.

I assume you do have the other table, don't you?

-- 
Alvaro Herrera                                http://www.CommandPrompt.com/
The PostgreSQL Company - Command Prompt, Inc.



view thread (13+ messages)  latest in thread

Message-ID: <20060601135310.GB18513@surnet.cl>
Permalink:  ../20060601135310.GB18513@surnet.cl/
Also on:    postgresql.org/message-id/20060601135310.GB18513@surnet.cl

 · 

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: alvherre@commandprompt.com, miroslav.sulc@startnet.cz
  Subject: Re: SELECT DISTINCT too slow
  In-Reply-To: <20060601135310.GB18513@surnet.cl>

* 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