Poor performance with ON DELETE CASCADE

From: Conal <Conal(dot)Tuohy(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org(dot)pgsql-performance(at)postgresql(dot)org
Subject: Poor performance with ON DELETE CASCADE
Date: 2007-09-25 05:41:44
Message-ID: 1190698904.122234.32760@o80g2000hse.googlegroups.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

I have a database schema which has a "central" table with several
others depending on it. The dependent tables all have foreign key
constraints with ON DELETE CASCADE so that I can remove tuples from
the "central" table and have the dependent rows removed automatically.
This all works, but it's very slow, and I can't see why. The dependent
tables are all indexed by this foreign key, so the deletions should be
very fast.

I have tried to use EXPLAIN and ANALYZE, and this tells me that the
deletion from the central table is not a problem, but that the
cascading deletions are very slow. e.g.

Trigger for constraint topic_map_object_parent_uid_fkey:
time=93063.837 calls=115

Unfortunately EXPLAIN doesn't provide any information about the
details of how it executes the cascading deletion; there's no query
plan for this, so I can't see why it is taking so long. Is it possible
to obtain a query plan for these "cascaded" delete queries?

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Petri Simolin 2007-09-25 05:57:42 UNIQUE_VIOLATION, Finding out which index would have been violated
Previous Message Phoenix Kiula 2007-09-25 05:36:26 [Urgent] Regexp_replace question