Re: Foreign keys and slow insert - Mailing list pgsql-general

From Richard Huxton
Subject Re: Foreign keys and slow insert
Date
Msg-id 42A719A2.2060804@archonet.com
Whole thread Raw
In response to Foreign keys and slow insert  (Dan Black <fireworker@gmail.com>)
List pgsql-general
Dan Black wrote:
> I read in documentation that primary key doesn't require additional indexes
> but I could find nothing about foreign keys.
> Do I need to create additional indexes when I create foreign keys?
> Example:
> create table master

> create table slave

> Do I need to create index
>
> CREATE INDEX my_index
> ON slave
> USING btree
> (master_id);

Yes. The primary key uses a "UNIQUE INDEX" to enforce uniqueness, so you
get the index for "free". The foreign-key has no such constraint of course.

--
   Richard Huxton
   Archonet Ltd

pgsql-general by date:

Previous
From: Stephan Szabo
Date:
Subject: Re: Foreign keys and slow insert
Next
From: Tom Lane
Date:
Subject: Re: Copying data from int column to array column