Re: SELECT DISTINCT too slow - Mailing list pgsql-sql

From Alvaro Herrera
Subject Re: SELECT DISTINCT too slow
Date
Msg-id 20060601135310.GB18513@surnet.cl
Whole thread Raw
In response to SELECT DISTINCT too slow  (Miroslav Šulc <miroslav.sulc@startnet.cz>)
Responses Re: SELECT DISTINCT too slow
List pgsql-sql
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.


pgsql-sql by date:

Previous
From: Rod Taylor
Date:
Subject: Re: Table design question
Next
From: Miroslav Šulc
Date:
Subject: Re: SELECT DISTINCT too slow