pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Josh Berkus <josh@agliodbs.com>
To: Bret Hughes <bhughes@elevating.com>
To: postgresql sql list <pgsql-sql@postgresql.org>
Subject: Re: distinct values without seq scan
Date: Wed, 7 Apr 2004 08:43:06 -0700
Message-ID: <200404070843.06144.josh@agliodbs.com> (raw)
In-Reply-To: <1081271194.18380.156.camel@bretsony>
References: <1081271194.18380.156.camel@bretsony>

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



view thread (2+ messages)

Message-ID: <200404070843.06144.josh@agliodbs.com>
Permalink:  ../200404070843.06144.josh@agliodbs.com/
Also on:    postgresql.org/message-id/200404070843.06144.josh@agliodbs.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, bhughes@elevating.com
  Subject: Re: distinct values without seq scan
  In-Reply-To: <200404070843.06144.josh@agliodbs.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