Re: select distinct and index usage

From: Alvaro Herrera <alvherre(at)commandprompt(dot)com>
To: Gregory Stark <stark(at)enterprisedb(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, David Wilson <david(dot)t(dot)wilson(at)gmail(dot)com>, Alban Hertroys <dalroi(at)solfertje(dot)student(dot)utwente(dot)nl>, pgsql-general(at)postgresql(dot)org
Subject: Re: select distinct and index usage
Date: 2008-04-08 12:48:40
Message-ID: 20080408124839.GE5290@alvh.no-ip.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Fernando Hevia 2008-04-08 13:23:06 Re: Removing Context messages
Previous Message Zdenek Kotala 2008-04-08 11:49:41 Re: "too many trigger records found for relation xyz"