From: | Csaba Nagy <nagy(at)ecircle-ag(dot)com> |
---|---|
To: | gerhard <g(dot)hintermayer(at)inode(dot)at> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: DELETE running at snail-speed |
Date: | 2008-12-18 14:26:42 |
Message-ID: | 1229610402.32039.17.camel@PCD12478 |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On Thu, 2008-12-18 at 05:29 -0800, gerhard wrote:
> I suspect the foreign key constraint of downtime_detail to slow down
> the delete process. Is this a bug, probably fixed in latest version
> (8.1.x) or should I drop the constraint and recreate after deletion -
> which I only see as workaround ?
The foreign key is the cause indeed, but you should put an index on
downtime_detail(downtimeid) and it would work fine. What happens is that
for each row you delete from 'downtime' table, the following is done by
the foreign key triggers (cascade the deletion to the child tables):
delete from downtime_detail where downtimeid = $1
You can try to see what kind of plan you get for that by:
prepare test_001(integer) as delete from downtime_detail where
downtimeid = $1;
explain execute test_001(0);
Now multiply whatever you get there by the count of rows deleted from
'downtime' and you'll get the reason why it is slow... then try it again
with the above mentioned index in place.
Cheers,
Csaba.
From | Date | Subject | |
---|---|---|---|
Next Message | Sam Mason | 2008-12-18 14:30:54 | Re: DELETE running at snail-speed |
Previous Message | Tom Lane | 2008-12-18 14:21:28 | Re: DELETE running at snail-speed |