pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: TimothyReaves@westfieldgrp.com
To: pgsql-sql@postgresql.org
Subject: Re: How slow is DISTINCT?
Date: Thu, 28 Feb 2002 08:45:25 -0500
Message-ID: <OF6974336F.BD066288-ON85256B6E.004B7A3B@westfield-cos.com> (raw)

Wei Weng wrote:

> Josh Berkus wrote:
>
>>Wei Wang,
>>
>>
>>
>>>How exactly slow is DISTINCT being processed in SQL engines? (not
>>>limited to postgresql, though comments on postgresql would be most
>>>relevant)
>>>
>>>
>>I can only give you a relative result, based exlusively on my anecdotal
>> experience with 7.1:
>>
>>Fast:  SELECT ...
>>Slower: SELECT ... GROUP BY x,y,z
>>     or:  SELECT DISCTINCT ON (x) ... (Postgres non-standard extension)
>>SLowest: SELECT DISTINCT ...
>>
>>The reason for this is that SELECT DISTINCT is effectively a GROUP BY
>> on all result fields of the query, and if a few of the aren't indexed
>> that requires a seq scan.
>>
> What if I do thing like
>
> SELECT DISTINCT table1.tid, table1.name, table1.description FROM ...
>
> Does it equal to the scenario 2 or 3?
>
> I am thinking SELECT DISTINCT table1.tid is just a variation (or the
> other way around) of SELECT DISTINCT ON (table1.tid), is that right?
>
> Thanks
>
>

     Of course, a more basic question is, why so much repeated data?
Perhaps you should look at the design in your tables.  I'm not assuming
they are wrong, only suggesting that you look.




view thread (10+ messages)  latest in thread

Message-ID: <OF6974336F.BD066288-ON85256B6E.004B7A3B@westfield-cos.com>
Permalink:  ../OF6974336F.BD066288-ON85256B6E.004B7A3B@westfield-cos.com/
Also on:    postgresql.org/message-id/OF6974336F.BD066288-ON85256B6E.004B7A3B@westfield-cos.com

 · 

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-sql@postgresql.org
  Cc: TimothyReaves@westfieldgrp.com
  Subject: Re: How slow is DISTINCT?
  In-Reply-To: <OF6974336F.BD066288-ON85256B6E.004B7A3B@westfield-cos.com>
  References: <OF6974336F.BD066288-ON85256B6E.004B7A3B@westfield-cos.com>

* 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