Search Postgresql Archives

Re: Foreign keys and slow insert

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

 



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

---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

              http://archives.postgresql.org

[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