For a writeless transaction which is cheaper/quicker: COMMIT or ROLLBACK?

て烟熏妆下的殇ゞ 提交于 2019-12-24 02:43:14

问题


I'm using sql transactions as containers for APPLOCKS and other concurrency mechanisms and so I sometimes create transactions at various isolation levels which only read data and don't write. I believe that in these situations, logically, COMMIT and ROLLBACK have identical outcomes.

For performance reasons, I'd like to know which one is cheaper/quicker for the server to execute? Is unavoidable bookkeeping required that is optimized for the COMMIT case and additional overhead for ROLLBACK even if there are no writes? Locks will be released in either case.

If it doesn't matter, then I don't have to litter my .NET TransactionScope code with an unnecessary scope.Complete() which might make me hesitate when reviewing code of an otherwise-obviously-read-only operation.

Thanks!


回答1:


As you are not writing anything, you should go for Commit as it in addition to closing the transaction it also releases any locks you may have had. Though technically Rollback will also do the same, but Commit is always faster then rollback.



来源:https://stackoverflow.com/questions/18473280/for-a-writeless-transaction-which-is-cheaper-quicker-commit-or-rollback

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!