From: Tom Lane <tgl@sss.pgh.pa.us>
To: Burak Seydioglu <buraks78@gmail.com>
Cc: pgsql-performance@postgresql.org
Subject: Re: indexes on primary and foreign keys
Date: Wed, 11 Jan 2006 18:06:33 -0500
Message-ID: <29042.1137020793@sss.pgh.pa.us> (raw)
In-Reply-To: <1b8a973c0601111438m3e0b1cc0hf9c387a4a1d6791d@mail.gmail.com>
References: <1b8a973c0601111438m3e0b1cc0hf9c387a4a1d6791d@mail.gmail.com>
Burak Seydioglu <buraks78@gmail.com> writes:
> I do a load of sql joins using primary and foreign keys. What i would like
> to know if PostgreSQL creates indexes on these columns automatically (in
> addition to using them to maintain referential integrity) or do I have to
> create an index manually on these columns as indicated below?
Indexes are only automatically created where needed to enforce a UNIQUE
constraint. That includes primary keys, but not foreign keys.
Note that you only really need an index on the referencing (non-unique)
side of a foreign key if you are worried about performance of DELETEs
or key changes on the referenced table. If you seldom or never do that,
you might want to dispense with the index.
regards, tom lane
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-performance@postgresql.org
Cc: tgl@sss.pgh.pa.us, buraks78@gmail.com
Subject: Re: indexes on primary and foreign keys
In-Reply-To: <29042.1137020793@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox