Re: Foreign keys

From: Rob Sargent <robjsargent(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Foreign keys
Date: 2013-12-18 18:10:03
Message-ID: 52B1E4FB.5010902@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 12/18/2013 11:02 AM, Dean Gibson (DB Administrator) wrote:
> I have general question about FOREIGN KEYs:
>
> 1. Suppose I have table A with primary key X, and another table B
> with field Y.
> 2. When I 'ALTER TABLE "B" ADD FOREIGN KEY( "Y" ) REFERENCES "A"
> ON UPDATE CASCADE ON DELETE CASCADE', that clearly spends some
> time building a separate index. Since there is already a unique
> index on X, presumably (?) the index being built is on Y.
> 3. However, the PostgreSQL documentation seems to indicate that it's
> a good idea to also separately create an index on Y.
> 4. Why, and why is the FOREIGN KEY index different from the ones on X
> and Y in any way but trivial?
> 5. If I need the separate index on Y, should it be built before or
> after the FOREIGN KEY constraint?
>
>
> --
> Mail to my list address MUST be sent via the mailing list.
> All other mail to my list address will bounce.
Perhaps you
wanthttp://www.postgresql.org/docs/9.3/static/sql-altertable.html
add table_constraint_using_index

In response to

  • Foreign keys at 2013-12-18 18:02:04 from Dean Gibson (DB Administrator)

Browse pgsql-general by date

  From Date Subject
Next Message Kevin Grittner 2013-12-18 18:41:01 Re: Foreign keys
Previous Message Dean Gibson (DB Administrator) 2013-12-18 18:02:04 Foreign keys