pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Josh Berkus <josh@agliodbs.com>
To: wweng@kencast.com
To: pgsql-sql@postgresql.org
Subject: Re: How slow is DISTINCT?
Date: Wed, 27 Feb 2002 13:45:16 -0800
Message-ID: <web-812107@davinci.ethosmedia.com> (raw)
In-Reply-To: <3C7D252A.3030608@kencast.com>

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.

If performance is an issue, you may wish to consider restructuring your
 queries and/or data model to eliminate the actual duplicate rows.

-Josh



view thread (10+ messages)  latest in thread

Message-ID: <web-812107@davinci.ethosmedia.com>
Permalink:  ../web-812107@davinci.ethosmedia.com/
Also on:    postgresql.org/message-id/web-812107@davinci.ethosmedia.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 using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: josh@agliodbs.com, wweng@kencast.com
  Subject: Re: How slow is DISTINCT?
  In-Reply-To: <web-812107@davinci.ethosmedia.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