Search Postgresql Archives

Re: Foreign keys

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Dean Gibson (DB Administrator) <postgresql@xxxxxxxxxxxx> 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.

No it doesn't.  If you are observing activity at that time, it is
probably from validating that the constraint is initially valid.

>    3. However, the PostgreSQL documentation seems to indicate
>       that it's a good idea to also separately create an index on
>       Y.

It *often* is, but there are various reasons you might not want
such an index, which is why its creation is not automatic.

>    5. If I need the separate index on Y, should it be built
>       before or after the FOREIGN KEY constraint?

In some cases it may allow faster initial validation of the
constraint; if I wanted the index I would probably build it before
adding the constraint.

--
Kevin Grittner
EDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


-- 
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general





[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux