From: Tom Lane <tgl@sss.pgh.pa.us>
To: arnaulist@andromeiberica.com
Cc: pgsql-admin@postgresql.org
Subject: Re: Delete performance
Date: Thu, 23 Feb 2006 11:35:00 -0500
Message-ID: <22825.1140712500@sss.pgh.pa.us> (raw)
In-Reply-To: <43FD8E1F.8020704@andromeiberica.com>
References: <1c66bda80602202302u2f6f6bc0jcfc3c728940ad2d0@mail.gmail.com>
<15417.1140534087@sss.pgh.pa.us>
<43FC2A5E.4080601@andromeiberica.com>
<11337.1140618701@sss.pgh.pa.us>
<43FD8E1F.8020704@andromeiberica.com>
Arnau <arnaulist@andromeiberica.com> writes:
>> The referencED column is forced to have an index. The referencING
>> column is not. The cases where you need an index on the latter are
>> precisely updates/deletes of the referencED column.
> Lets put an example
> CREATE TABLE departments
> (
> id INT2
> CONSTRAINT pk_dept_id PRIMARY KEY,
> name VARCHAR(50)
> CONSTRAINT nn_dept_name NOT NULL
> );
> CREATE TABLE users
> (
> id INT8
> CONSTRAINT pk_users_id PRIMARY KEY,
> name VARCHAR(50)
> CONSTRAINT nn_users_name NOT NULL,
> department_id INT2
> CONSTRAINT fk_users_deptid REFERENCES departments(id)
> CONSTRAINT nn_users_deptid NOT NULL
> )
> Do we should create the following index?
> CREATE INDEX idx_users_deptid ON users(department_id)
Yes, if you are concerned about the performance of updates/deletes on
the departments table. The reason the system doesn't make such an index
automatically is that there are common scenarios where you seldom or
never update the master table, and so the index wouldn't repay the cost
it creates for updates of the slave table.
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 from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-admin@postgresql.org
Cc: tgl@sss.pgh.pa.us, arnaulist@andromeiberica.com
Subject: Re: Delete performance
In-Reply-To: <22825.1140712500@sss.pgh.pa.us>
References: <1c66bda80602202302u2f6f6bc0jcfc3c728940ad2d0@mail.gmail.com> <15417.1140534087@sss.pgh.pa.us> <43FC2A5E.4080601@andromeiberica.com> <11337.1140618701@sss.pgh.pa.us> <43FD8E1F.8020704@andromeiberica.com> <22825.1140712500@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