Re: How slow is DISTINCT?

From: "Josh Berkus" <josh(at)agliodbs(dot)com>
To: wweng(at)kencast(dot)com, Josh Berkus <josh(at)agliodbs(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: How slow is DISTINCT?
Date: 2002-02-27 22:54:39
Message-ID: web-812221@davinci.ethosmedia.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Wei,

> SELECT DISTINCT table1.tid, table1.name, table1.description FROM ...
>
> Does it equal to the scenario 2 or 3?

Three.

> 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?

Wrong. SELECT DISTINCT ON table1.tid takes the table1.tid field and
the first related other data it can find. SELECT DISTINCT looks for
the unique combinaiton of all fields selected. In a multi-table, many
field query, the former is faster than the latter bceause less data is
being checked for uniqueness, and extra data is simply discarded.

Tom, please correct me if I'm totally out on a limb, here.

-Josh

______AGLIO DATABASE SOLUTIONS___________________________
Josh Berkus
Complete information technology josh(at)agliodbs(dot)com
and data management solutions (415) 565-7293
for law firms, small businesses fax 621-2533
and non-profit organizations. San Francisco

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Wei Weng 2002-02-27 22:57:46 Re: How slow is DISTINCT?
Previous Message Josh Berkus 2002-02-27 21:45:16 Re: How slow is DISTINCT?