Poor performance with ON DELETE CASCADE - Mailing list pgsql-general

From Conal
Subject Poor performance with ON DELETE CASCADE
Date
Msg-id 1190698904.122234.32760@o80g2000hse.googlegroups.com
Whole thread Raw
Responses Re: Poor performance with ON DELETE CASCADE
List 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?


pgsql-general by date:

Previous
From: Johann Maar
Date:
Subject: Autostart PostgreSQL in Ubuntu
Next
From: Petri Simolin
Date:
Subject: UNIQUE_VIOLATION, Finding out which index would have been violated