Re: Delete performance

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: arnaulist(at)andromeiberica(dot)com
Cc: pgsql-admin(at)postgresql(dot)org
Subject: Re: Delete performance
Date: 2006-02-23 16:35:00
Message-ID: 22825.1140712500@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

Arnau <arnaulist(at)andromeiberica(dot)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

In response to

Responses

Browse pgsql-admin by date

  From Date Subject
Next Message Arnau 2006-02-23 16:45:12 Re: Delete performance
Previous Message Andy Shellam 2006-02-23 16:28:34 Re: Deinstallation