Re: select distinct, index not used

From: Sam Mason <sam(at)samason(dot)me(dot)uk>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: select distinct, index not used
Date: 2009-04-16 16:42:48
Message-ID: 20090416164247.GP12225@frubble.xen.chris-lamb.co.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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/

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2009-04-16 16:48:43 Re: select distinct, index not used
Previous Message Dongyan Song 2009-04-16 16:31:14 Re: a question about postgresql server connection