Re: select distinct, index not used - Mailing list pgsql-general

From Sam Mason
Subject Re: select distinct, index not used
Date
Msg-id 20090416164247.GP12225@frubble.xen.chris-lamb.co.uk
Whole thread Raw
In response to Re: select distinct, index not used  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: select distinct, index not used
List pgsql-general
On Thu, Apr 16, 2009 at 11:29:25AM -0400, Tom Lane wrote:
> , a full table indexscan isn't going to be particularly fast in
> any case; it's often the case that seqscan-and-sort is the right
> decision.

Is PG capable of "skipping" over duplicate values using an index?

For example, if I've got a table like:

  CREATE TABLE foo (
    id INTEGER PRIMARY KEY,
    v1 BOOLEAN
  );

that contains several million rows and I do a query like:

  SELECT DISTINCT v1 FROM foo;

PG should only need to read three tuples from the table (assuming there
are no dead rows).  I've had a look in the TODO, but haven't found
anything similar.  This is obviously only a win when there are few
distinct values from compared to the number of rows.

--
  Sam  http://samason.me.uk/

pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: select distinct, index not used
Next
From: Tom Lane
Date:
Subject: Re: select distinct, index not used