문제

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!

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top