简体   繁体   中英

Is it good to delete when reading ( adding each statement to delete ) and doing a batch delete at the end or do a single delete?

Archive and delete process. Which one is recommended?

This process runs end of the day when the window is closed to any extraneous transactions other than this one to disallow interference with the below tx.

I. Batch delete

object = read()

while ( hasNext() ) 
{
  object = next();
  call the archive_process to archive the object.
  add to delete.
}

batch_delete.

II. Single delete statement.

object = read()

while ( hasNext() ) 
{
  object = next();
  call the archive_process to archive the object.
}

use the same sql as above, but instead delete in a single statement.

Which one is recommended?

It all depends on your specific needs:

  • If your code require that every record is deleted so it can perform other tasks, deleting one row at a time on each loop may be needed.
  • If your code can do its tasks independently of wether a record is deleted or not, deleting everything at the end (on a single batch) would be better.

You need to remember that every delete triggers an action on your data, and may have an impact on disk read-write speed of your program. A single batch delete may have a positive impact on the speed of your code compared with many one-row delete operations.

As addition to other answers - check also you have enough UNDO to support DELETE command. Also, with bigger volume DELETE can become tooo slow - check if alternatives exist. Be aware also of the impact of many indexes.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM