Thread: Index Question

Index Question

From
"Bierbryer, Andrew"
Date:

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

 

 

Re: Index Question

From
Tom Lane
Date:
"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