Re: Join Table - Mailing list pgsql-sql

From Tom Lane
Subject Re: Join Table
Date
Msg-id 14976.1099328858@sss.pgh.pa.us
Whole thread Raw
In response to Join Table  (T E Schmitz <mailreg@numerixtechnology.de>)
List pgsql-sql
T E Schmitz <mailreg@numerixtechnology.de> writes:
> CREATE TABLE SUPPLY
> (
> ITEM_FK integer NOT NULL,
> CONTACT_FK integer NOT NULL,
> COST numeric (7,2),
> PRIMARY KEY (ITEM_FK,CONTACT_FK)
> );

> Question: is it necessary/advisable to create an index for the ITEM_FK 
> column? Or is this redundantbecause this column is already one of the PK 
> columns?

The PK index will be usable for searches on ITEM_FK alone (though *not*
for searches on CONTACT_FK alone --- a moment's thought about the index
sort order should convince you why).  It would be marginally less
efficient for this purpose than a dedicated index on ITEM_FK.  But unless
your use of this table is almost all searches and hardly any
modifications, adding a dedicated index is probably a net loss due to
the added update costs.
        regards, tom lane


pgsql-sql by date:

Previous
From: Michael Fuhr
Date:
Subject: Re: Join Table
Next
From: Richard Huxton
Date:
Subject: Re: Join Table