Re: Storage of Foreign Keys

From: Lew <noone(at)lwsc(dot)ehost-services(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Storage of Foreign Keys
Date: 2009-09-22 17:32:32
Message-ID: h9b1ng$jdj$1@news.albasani.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Scott Marlowe wrote:
> On Mon, Sep 21, 2009 at 11:09 AM, Alan Hodgson <ahodgson(at)simkin(dot)ca> wrote:
>> On Monday 21 September 2009, Christian Koetschan
>> <c(dot)koetschan(at)biozentrum(dot)uni-wuerzburg(dot)de> wrote:
>>> Is everything I insert into mycolA and mycolB stored twice, or
>>> is there something like a pointer/reference from mycolA to the things
>>> stored in mycolB?
>>>
>> It's stored twice and for performance you need to index it in both tables.
>> If you put ON UPDATE CASCADE on it, an update to the master will hit both
>> tables though.
>
> Slight correction. You might need to index it on both ends for
> performance. There are some instances where the referencing table
> only ever has a few rows in it, and in those cases, you likely don't
> need an index.

And it is likely that the referenced table has an index since foreign keys
reference a primary key or unique-constrained (combination of) column(s).

--
Lew

In response to

Browse pgsql-general by date

  From Date Subject
Next Message dan06 2009-09-22 17:43:09 Resources for learning PostgreSQL
Previous Message Emanuel Calvo Franco 2009-09-22 17:23:12 Re: citext like query and index usage