Re: SELECT DISTINCT very slow

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Ben Harper <rogojin(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: SELECT DISTINCT very slow
Date: 2009-07-09 15:56:26
Message-ID: 162867790907090856s347ede5bl8dfceec3ec9d933c@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hello

when you use older pg than 8.3, please, use GROUP BY.

SELECT field FROM table GROUP BY field.

Regards
Pavel Stehule

2009/7/9 Ben Harper <rogojin(at)gmail(dot)com>:
> Hi,
> Can anybody explain this:
>
> Records: 600,000
> Field Width: Approximately 20 UTF8 characters - type is VARCHAR(25)
> Field is Indexed.
>
> SELECT DISTINCT field FROM table;
>
> Takes about 6 seconds. There are 111 distinct items.
>
> On Sqlite, and another place where I have a B+Tree, this query is
> faster than my eye can measure.
>
> Is this a well known issue?
>
> Thanks,
> Ben
>
> --
> Sent via pgsql-general mailing list (pgsql-general(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-general
>

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Dan Armbrust 2009-07-09 16:03:00 Re: Checkpoint Tuning Question
Previous Message Andres Freund 2009-07-09 15:47:38 Re: SELECT DISTINCT very slow