Re: Creating a foreign key

From: PFC <lists(at)peufeu(dot)com>
To: "Campbell, Lance" <lance(at)uiuc(dot)edu>, pgsql-performance(at)postgresql(dot)org
Subject: Re: Creating a foreign key
Date: 2008-05-08 20:02:47
Message-ID: op.uaupyxsecigqcu@apollo13.peufeu.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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.

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message PFC 2008-05-08 20:08:17 Re: Creating indexes
Previous Message Alan Hodgson 2008-05-08 19:52:30 Re: Creating indexes