Index Question

Started by Bierbryer, Andrewover 16 years ago2 messagesgeneral
Jump to latest
#1Bierbryer, Andrew
abierbryer@klsdiversified.com

I have created a table where a unique row is defined by 5 columns and
have created an index on these 5 columns. If I then do a select with a
where clause that only consists of 3 of these columns, will I get the
speed benefits from the index that I have created, or will I need to
create another index with only these 3 columns?

Thanks,

Andrew

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Bierbryer, Andrew (#1)
Re: Index Question

"Bierbryer, Andrew" <abierbryer@klsdiversified.com> writes:

I have created a table where a unique row is defined by 5 columns and
have created an index on these 5 columns. If I then do a select with a
where clause that only consists of 3 of these columns, will I get the
speed benefits from the index that I have created, or will I need to
create another index with only these 3 columns?

It should work fine if those are the three leading columns of the index.
If they're not, you might want another index. This is not specific at
all to unique keys, it's a general property of multicolumn indexes.
Read
http://www.postgresql.org/docs/8.4/static/indexes.html
particularly 11.3 and 11.5

regards, tom lane