X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id 10340D1C915 for ; Wed, 7 Apr 2004 12:43:20 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 63647-08 for ; Wed, 7 Apr 2004 12:43:17 -0300 (ADT) Received: from davinci.ethosmedia.com (server228.ethosmedia.com [209.128.84.228]) by svr1.postgresql.org (Postfix) with ESMTP id 6FB19D1B9AA for ; Wed, 7 Apr 2004 12:43:16 -0300 (ADT) Received: from [63.195.55.98] (HELO spooky) by davinci.ethosmedia.com (CommuniGate Pro SMTP 4.1.8) with ESMTP id 4790728; Wed, 07 Apr 2004 08:44:37 -0700 Content-Type: text/plain; charset="iso-8859-1" From: Josh Berkus Organization: Aglio Database Solutions To: Bret Hughes , postgresql sql list Subject: Re: distinct values without seq scan Date: Wed, 7 Apr 2004 08:43:06 -0700 User-Agent: KMail/1.4.3 References: <1081271194.18380.156.camel@bretsony> In-Reply-To: <1081271194.18380.156.camel@bretsony> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-Id: <200404070843.06144.josh@agliodbs.com> X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200404/56 X-Sequence-Number: 17431 Bret, > I have a table indexed on a char(35) field and want a query to return a > distinct list of the values in this column. Is there some syntactical > magic I can do to get these values without a sequential scan? I assume, > ( here we go again ) that these values are in the index somewhere and I > seem to recall a select DISTINCT using an index in DB2 way back when but > I may be mistaken. > > Searching the archives I found an email that indicated this was possible > in 7.4 and infact is the reason I upgraded from 7.2x. Well, leaving aside that you have a data normalization issue (these values should really be in a reference list with an FK), to take advantage of the 7.4 optimization, try: SELECT advertiser FROM logrecords GROUP BY advertiser ORDER BY advertiser; -- Josh Berkus Aglio Database Solutions San Francisco