Re: Delete performance - Mailing list pgsql-performance

From Pierre C
Subject Re: Delete performance
Date
Msg-id op.vwdb1pv8eorkce@apollo13
Whole thread Raw
In response to Delete performance  (Jarrod Chesney <jarrod.chesney@gmail.com>)
Responses Re: Delete performance  (Craig Ringer <craig@postnewspapers.com.au>)
List 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.

pgsql-performance by date:

Previous
From: Robert Haas
Date:
Subject: Re: Hash Anti Join performance degradation
Next
From: Cédric Villemain
Date:
Subject: Re: Hash Anti Join performance degradation