DeleteAll #107
Replies: 3 comments 3 replies
-
|
I totally agree and in the Microsoft base app there is this pattern Table.SetRange(field, value);
if not Table.IsEmpty() then
Table.DeleteAll(); // can be also Table.DeleteAll(true); |
Beta Was this translation helpful? Give feedback.
-
|
Why should we need to worry about things like this at the application level? Wouldn't it be much more efficient if the platform checked for the absence of any records (within the filter) before locking? |
Beta Was this translation helpful? Give feedback.
-
|
While I agree that this is best practice, I find that the rationale behind it is slightly misleading. DeleteAll does not perform an exclusive lock on any records if there are no records to delete. However, it does place an intent exclusive lock on the table. This means that if the intent exclusive lock is kept long enough, it would prevent lock escalations for other transactions, thus resulting in increased memory usage on the SQL server. Also, it means that if another transaction has already placed an incompatible lock on the table such as a shared lock or an exclusive lock (likely through lock escalation), the deleteall operation will be blocked even if there is nothing to delete. Alexander Drogin explains it with good examples here: |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
When you perform a "DeleteAll" when there is nothing to delete, it will still perform a lock. When you for example perform a DeleteAll on an empty table, it will result in a table lock.
Therefore it's good practice to always check if the table is empty when performing a DeleteAll.
Beta Was this translation helpful? Give feedback.
All reactions