Re: Delete performance

From: "Pierre C" <lists(at)peufeu(dot)com>
To: pgsql-performance(at)postgresql(dot)org, "Jarrod Chesney" <jarrod(dot)chesney(at)gmail(dot)com>
Subject: Re: Delete performance
Date: 2011-05-31 23:11:39
Message-ID: op.vwdb1pv8eorkce@apollo13
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

> If i run 30,000 prepared "DELETE FROM xxx WHERE "ID" = ?" commands it
> takes close to 10 minutes.

Do you run those in a single transaction or do you use one transaction per
DELETE ?

In the latter case, postgres will ensure each transaction is commited to
disk, at each commit. Since this involves waiting for the physical I/O to
happen, it is slow. If you do it 30.000 times, it will be 30.000 times
slow.

Note that you should really do :

DELETE FROM table WHERE id IN (huge list of ids).

or

DELETE FROM table JOIN VALUES (list of ids) ON (...)

Also, check your foreign keys using cascading deletes have indexes in the
referencing tables. Without an index, finding the rows to cascade-delete
will be slow.

In response to

Responses

Browse pgsql-performance by date

  From Date Subject
Next Message Cédric Villemain 2011-06-01 00:43:05 Re: [PERFORM] Hash Anti Join performance degradation
Previous Message Robert Haas 2011-05-31 21:58:08 Re: Hash Anti Join performance degradation