Re: Problem Deleting Referenced records

From: Bruno Wolff III <bruno(at)wolff(dot)to>
To: Alex <alex(at)meerkatsoft(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Problem Deleting Referenced records
Date: 2003-11-11 19:02:46
Message-ID: 20031111190246.GB11772@wolff.to
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Wed, Nov 12, 2003 at 00:08:02 +0900,
Alex <alex(at)meerkatsoft(dot)com> wrote:
> Bruno,
> I am not sure why but the whole delete proces with the where not exists
> method took 3hrs, rather long I would say.
>
> Table A had 2.5mil records
> Table B had about 30k records
>
> In addition Table C with about 2 mil records referenced a referenced A
> (same key as B)
> In both A and B about 150k records where deleted... but the process took
> more than 3 hrs.
>
> Its pretty long I would say. I noticed in the past that if I had
> multiple foreign keys, referencing different tables like TableA <--
> TableB <-- TableC then deletes are really slow... sometimes in the area
> of one delete per second. Never really figured out why. (And yes I did
> run a Vacuum or Vacuum analyze on the DB
> or Tables).

If you do a lot of deleting of rows in referenced tables, then you probably
want to create indexes in the referencing tables for the key. This will
allow for quicker checks by the referential integrity checking triggers.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message mboscia 2003-11-11 19:12:45 change conndeferrable in pg_constraint?
Previous Message Marc G. Fournier 2003-11-11 18:42:55 Re: [ANNOUNCE] PostgreSQL v7.4 Release Candidate 2