Re: Are foreign key's automatically set as indicies?

From: PFC <lists(at)peufeu(dot)com>
To: camb <mvpaustralia(at)gmail(dot)com>, pgsql-general(at)postgresql(dot)org
Subject: Re: Are foreign key's automatically set as indicies?
Date: 2007-05-19 15:13:44
Message-ID: op.tskxw6p4cigqcu@apollo13
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Wed, 16 May 2007 06:09:15 +0200, camb <mvpaustralia(at)gmail(dot)com> wrote:

> Hey all,
> I'm sorta new to PG and am just wondering, when I create a foreign key
> is it automatically set as an indexed column or do I need to also set
> that manually?

Primary key creates unique index.
Foreign keys do not create any indexes, it is up to you to decide if you
need indexes or not.

Say :

CREATE TABLE items ( ... category_id REFERENCES categories( id ) )

if you want cascaded deletes/updates to your items table to be fast, or
you need it for other reasons, create an index on category_id.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Joris Dobbelsteen 2007-05-19 16:24:09 Re: Data replication through disk replication
Previous Message Raymond O'Donnell 2007-05-19 15:04:30 Re: Are foreign key's automatically set as indicies?