In PostgreSql which is more efficient bulk Update or delete?

Faiz Kidwai :

In my java web application, I need to delete a set of records from a table. I have 2 options:

  1. Directly run delete query from the application
  2. Update a value in all the records to hide them from the user view and let a daemon thread run and clean up these records in the background.

The number of records can range from 10 to 100000. My intent here is to know the efficient and safe way to do that without putting too much load on the server.

P.S.: Feel free to share any other suitable approach.

richyen :

Under the hood, an UPDATE is actually:

  1. Flag updated row as deleted
  2. Insert new row, which is a copy of the row in 1. above, but reflecting updated columns

Therefore, since an UPDATE operation involves two writes, a DELETE is actually more efficient, as it simply flags the deleted row, using one write (because of the Multi-Version Concurrency Control (MVCC) framework)

Disclosure: I work for EnterpriseDB (EDB)

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=322515&siteId=1