Re: Creating a foreign key - Mailing list pgsql-performance

From PFC
Subject Re: Creating a foreign key
Date
Msg-id op.uaupyxsecigqcu@apollo13.peufeu.com
Whole thread Raw
In response to Creating a foreign key  ("Campbell, Lance" <lance@uiuc.edu>)
List pgsql-performance
> When you create a foreign key to a table is there an index that is
> created on the foreign key automatically?

    No, Postgres doesn't do it for you, because if you create (ref_id)
references table.id, you will perhaps create an index on (ref_id, date)
which would then fill the purpose (and other purposes), or perhaps your
table will have 10 rows (but postgres doesnt' know that when you create
it) and having an index would be useless, or your table could have many
rows but only a few distinct referenced values, in which case again the
index would only slow things down.
    PG does not presume to know better than yourself what you're gonna do
with your data ;)
    UNIQUE and PRIMARY KEY do create UNIQUE INDEXes, of course.

pgsql-performance by date:

Previous
From: Asche
Date:
Subject: Re: Creating indexes
Next
From: PFC
Date:
Subject: Re: Creating indexes