-
-
Notifications
You must be signed in to change notification settings - Fork 316
Description
I ran into an issue where a batch delete became extremely slow because I'm deleting millions of records. My transaction log grew very big, causing the slowdown. After reproducing the issue in SSMS, I realized that adding a CHECKPOINT statement in the WHILE loop improved performance tremendously.
I propose that a boolean option (e.g. EnableCheckpoint
) should be added to batch deletes, making my suggestion opt-in. In some cases using CHECKPOINT is not desirable, because when using it and the batch delete fails, it will be partially committed already. I don't think the default behavior should be changed.
Are batch updates implemented similarly to batch deletes? (Does this library generate a WHILE loop in the SQL for batch updates?) If so, I propose a similar option should be added to batch updates as well.
You could take it one step further and add an additional option to force the batch delete to run under Simple Recovery Mode. This apparently can make it faster compared to Full Recovery Mode. See this for more information about that: https://stackoverflow.com/a/21100285/1185136. I'm not sure this approach is safe though, I wonder what happens when multiple batch deletes are running simultaneously and both of them are changing the recovery mode back and forth...