From: Tom Lane <tgl@sss.pgh.pa.us>
To: Miroslav Ć ulc <miroslav.sulc@startnet.cz>
Cc: pgsql-sql@postgresql.org
Subject: Re: SELECT DISTINCT too slow
Date: Thu, 01 Jun 2006 11:20:30 -0400
Message-ID: <12554.1149175230@sss.pgh.pa.us> (raw)
In-Reply-To: <447EEAF1.7040305@startnet.cz>
References: <447EEAF1.7040305@startnet.cz>
=?ISO-8859-2?Q?Miroslav_=A9ulc?= <miroslav.sulc@startnet.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
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: tgl@sss.pgh.pa.us, miroslav.sulc@startnet.cz
Subject: Re: SELECT DISTINCT too slow
In-Reply-To: <12554.1149175230@sss.pgh.pa.us>
* 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