Re: If an index is based on 3 columns will a query using two of the columns utilize the index? - Mailing list pgsql-general

From Greg Stark
Subject Re: If an index is based on 3 columns will a query using two of the columns utilize the index?
Date
Msg-id 87fysa2sch.fsf@stark.xeocode.com
Whole thread Raw
In response to Re: If an index is based on 3 columns will a query using two of the columns utilize the index?  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: If an index is based on 3 columns will a query using two of the columns utilize the index?
List pgsql-general
Tom Lane <tgl@sss.pgh.pa.us> writes:

> Alvaro Herrera <alvherre@alvh.no-ip.org> writes:
>
> > Yes, if it is selective enough.  (It _can_ use the index, which does not
> > mean that it _will_ use it.)  Note that if your example query used the
> > columns (lname, dob), the answer would be "no."
>
> Actually, that last point is not true anymore as of 8.1 --- see this
> thread:
> http://archives.postgresql.org/pgsql-hackers/2005-05/msg00939.php
> which led to this patch:
> http://archives.postgresql.org/pgsql-committers/2005-06/msg00156.php

Did that patch actually implement "skip scanning"?

The comment seems to only describe removing the restriction from the planner.
Which would make it theoretically possible but presumably the the cost
estimator should ensure it essentially never gets chosen for btree indexes.
The btree index would very very rarely help since it would require a complete
index scan.

I guess I could see some corner cases where it would help. Very wide tables
with an index on a few very selective relatively narrow columns. So the index
could be scanned in its entirety much faster than a full table scan. But the
index would have to be *much* narrower than the table and quite selective
to overcome the random access penalty.

Skip scanning would make it much more likely to be helpful.

Also, I think Oracle has another scan method called a "fast index scan" that
basically does a full sequential scan of the index. So the tuples come out
unordered but the access pattern is sequential. Would that be a good TODO for
Postgres? Is it feasible given the index disk structures in Postgres?

--
greg

pgsql-general by date:

Previous
From: Teodor Sigaev
Date:
Subject: Re: If an index is based on 3 columns will a query using
Next
From: Janning Vygen
Date:
Subject: Re: ERROR: type "temp_gc" already exists