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

Are foreign key's automatically set as indicies?

From
camb
Date:
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?

Thanks in advance,
Cam


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

From
Raymond O'Donnell
Date:
On 16/05/2007 05:09, camb wrote:

> 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?

AFAIK you need to create the index separately. I use PgAdmin most of the
time, which does that by default, so I'm a bit hazy on doing it by hand.

Ray.

---------------------------------------------------------------
Raymond O'Donnell, Director of Music, Galway Cathedral, Ireland
rod@iol.ie
---------------------------------------------------------------

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

From
PFC
Date:
On Wed, 16 May 2007 06:09:15 +0200, camb <mvpaustralia@gmail.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.