Re: Why CASCADE constraint takes more time when table is loaded with huge records? - Mailing list pgsql-general

From David Johnston
Subject Re: Why CASCADE constraint takes more time when table is loaded with huge records?
Date
Msg-id DC4A0E81-93BC-43CC-AE22-A941B6D119F7@yahoo.com
Whole thread Raw
In response to Why CASCADE constraint takes more time when table is loaded with huge records?  (Siva Palanisamy <siva_p@hcl.com>)
List pgsql-general
On Nov 22, 2011, at 4:32, Siva Palanisamy <siva_p@hcl.com> wrote:

Hi ya,

 

As I had raised a question here at ‘Please recommend the best bulk-delete option’ (http://stackoverflow.com/questions/8172101/please-recommend-the-best-bulk-delete-option), CASCADE constraint is the one that prevents me to delete all the records in all the tables when they were loaded with bulk records. Is there any reason for why CASCADE takes time when DELETE FROM table1; Or TRUNCATE table1 CASCADE is attempted? FYI, I'm using PostgreSQL 8.1.4. Though outdated, when I remove CASCADE constraint in my table structures (listed in the top link), both DELETE and TRUNCATE queries work fine and completes quickly. However, CASCADE is what I needed! I can't just remove the constraint. Please help me on this.

 

Regards,

Siva.



Cascading is a convenience, not a necessity.  It takes time because you have to find and delete each related record on the other tables.

My only possible guess is your FK fields on the related tables are not indexed.  Create indexes on them and see how much performance improves.

David J.

pgsql-general by date:

Previous
From: Raghavendra
Date:
Subject: Re: Installing postgresql on windows 7
Next
From: Reid Thompson
Date:
Subject: Is this safe to perform on PostgreSQL 8.3.7 -> Resize a column in a PostgreSQL table without changing data