Re: Why CASCADE constraint takes more time when table is loaded with huge records?

From: David Johnston <polobo(at)yahoo(dot)com>
To: Siva Palanisamy <siva_p(at)hcl(dot)com>
Cc: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Why CASCADE constraint takes more time when table is loaded with huge records?
Date: 2011-11-22 14:25:24
Message-ID: DC4A0E81-93BC-43CC-AE22-A941B6D119F7@yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Nov 22, 2011, at 4:32, Siva Palanisamy <siva_p(at)hcl(dot)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.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Reid Thompson 2011-11-22 14:50:05 Is this safe to perform on PostgreSQL 8.3.7 -> Resize a column in a PostgreSQL table without changing data
Previous Message Raghavendra 2011-11-22 13:13:45 Re: Installing postgresql on windows 7