Re: SELECT DISTINCT too slow

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Miroslav Šulc <miroslav(dot)sulc(at)startnet(dot)cz>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: SELECT DISTINCT too slow
Date: 2006-06-01 15:20:30
Message-ID: 12554.1149175230@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

=?ISO-8859-2?Q?Miroslav_=A9ulc?= <miroslav(dot)sulc(at)startnet(dot)cz> writes:
> 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

Try
SELECT Key FROM MRTPContactValue GROUP BY Key

The "select distinct" code is a bit old and crufty, GROUP BY is usually
smarter.

regards, tom lane

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Miroslav Šulc 2006-06-01 15:39:48 Re: SELECT DISTINCT too slow
Previous Message Miroslav Šulc 2006-06-01 15:03:22 Re: SELECT DISTINCT too slow