Re: Slow Bulk Delete

From: "Pierre C" <lists(at)peufeu(dot)com>
To: thilo <thilo(dot)tanner(at)gmail(dot)com>, pgsql-performance(at)postgresql(dot)org
Subject: Re: Slow Bulk Delete
Date: 2010-05-17 10:10:31
Message-ID: op.vcug7tj0eorkce@immo.peufeu.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

> DELETE FROM table1 WHERE table2_id = ?

For bulk deletes, try :

DELETE FROM table1 WHERE table2_id IN (list of a few thousands ids)

- or use a JOIN delete with a virtual VALUES table
- or fill a temp table with ids and use a JOIN DELETE

This will save cliet/server roundtrips.

Now, something that can make a DELETE very slow is a non-indexed ON DELETE
CASCADE foreign key : when you DELETE FROM table1 and it cascades to a
DELETE on table2, and you forget the index on table2. Also check the time
spent in triggers. Do you have a GIN index ?

In response to

Responses

Browse pgsql-performance by date

  From Date Subject
Next Message Scott Marlowe 2010-05-17 10:25:24 Re: old server, new server, same performance
Previous Message Piotr Legiecki 2010-05-17 09:52:17 Re: old server, new server, same performance