Re: select distinct and index usage - Mailing list pgsql-general

From Alvaro Herrera
Subject Re: select distinct and index usage
Date
Msg-id 20080408124839.GE5290@alvh.no-ip.org
Whole thread Raw
In response to Re: select distinct and index usage  (Gregory Stark <stark@enterprisedb.com>)
List pgsql-general
Gregory Stark escribió:

> I thought our DISTINCT index scan does do that but it still has to read the
> index leaf pages sequentially. It doesn't back-track up the tree structure and
> refind the next key.

The way to back-track is to start the scan over from the root page down,
keeping a stack of parent pages as you go down (mainly because we need
to lock them in order, topmost first).  So it's not a particularly cheap
operation.  I'm not sure the situation with thousands of equal keys is
common enough to warrant adding all the code that would be needed to
implement the kind of "distinct scan" that you suggest, even though it
certainly is a nice idea.

--
Alvaro Herrera                                http://www.CommandPrompt.com/
The PostgreSQL Company - Command Prompt, Inc.

pgsql-general by date:

Previous
From: Sim Zacks
Date:
Subject: dirty select
Next
From: "Fernando Hevia"
Date:
Subject: Re: Removing Context messages