Received: from davinci.ethosmedia.com (davinci.ethosmedia.com [209.10.40.250]) by postgresql.org (Postfix) with ESMTP id 3A18A475991 for ; Wed, 27 Feb 2002 17:54:39 -0500 (EST) Received: from [209.10.40.250] (account ) by davinci.ethosmedia.com (CommuniGate Pro WebUser 3.5.2) with HTTP id 812221; Wed, 27 Feb 2002 14:54:39 -0800 From: "Josh Berkus" Subject: Re: How slow is DISTINCT? To: wweng@kencast.com, Josh Berkus Cc: pgsql-sql@postgresql.org X-Mailer: CommuniGate Pro Web Mailer v.3.5.2 Date: Wed, 27 Feb 2002 14:54:39 -0800 Message-ID: In-Reply-To: <3C7D646A.8070804@kencast.com> MIME-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 8bit X-Archive-Number: 200202/444 X-Sequence-Number: 6865 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@agliodbs.com and data management solutions (415) 565-7293 for law firms, small businesses fax 621-2533 and non-profit organizations. San Francisco