Re: deleting rows with foreign keys

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Tom Allison <tom(at)tacocat(dot)net>
Cc: Postgres General <pgsql-general(at)postgresql(dot)org>
Subject: Re: deleting rows with foreign keys
Date: 2007-07-11 23:24:27
Message-ID: 4596.1184196267@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Tom Allison <tom(at)tacocat(dot)net> writes:
> I have ~250K rows in this table.
> the token_idx is referenced in two other tables, both of whom have a
> foreign key constraint to ON DELETE CASCADE.
> Of the other two tables, one has ~1M rows and the other ~350K rows.

> Problem:
> Deleting one row can take 2 seconds.

> Is there something I can do to improve the speed.

Put indexes on the referencing columns. Without that, a seqscan is
required to look for referencing rows.

regards, tom lane

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2007-07-11 23:36:18 Re: [GENERAL] Count(*) throws error
Previous Message Tom Allison 2007-07-11 23:11:16 deleting rows with foreign keys