Skip site navigation (1) Skip section navigation (2)

Peripheral Links

Header And Logo

PostgreSQL
| The world's most advanced open source database.

Site Navigation

Search for
  Advanced Search

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@postgresql.org
  • Subject: Poor performance with ON DELETE CASCADE
  • Date: Tue, 25 Sep 2007 05:41:44 -0000
  • Message-id: <1190698904(dot)122234(dot)32760(at)o80g2000hse(dot)googlegroups(dot)com>

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?




Home | Main Index | Thread Index

Privacy Policy | PostgreSQL Archives hosted by Command Prompt, Inc. | Designed by tinysofa
Copyright © 1996 – 2008 PostgreSQL Global Development Group