对于便宜/快速的无写事务:COMMIT或ROLLBACK? [英] For a writeless transaction which is cheaper/quicker: COMMIT or ROLLBACK?

查看:45
本文介绍了对于便宜/快速的无写事务:COMMIT或ROLLBACK?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将sql事务用作APPLOCKS和其他并发机制的容器,因此有时我会在各种隔离级别创建事务,这些事务仅读取数据而未写入.我相信,在这种情况下,从逻辑上讲,COMMIT和ROLLBACK具有相同的结果.

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.

出于性能方面的考虑,我想知道哪一种服务器更便宜/更快捷?即使没有写操作,是否也需要针对COMMIT案例进行优化的不可避免的簿记和ROLLBACK的额外开销?无论哪种情况,锁都将被释放.

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.

如果没关系,那么我不必用不必要的 scope.Complete()填充.NET TransactionScope代码,这可能会让我在查看否则的代码时犹豫不决-显然是只读的操作.

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.

谢谢!

推荐答案

由于您未编写任何内容,因此应选择Commit,因为它除了关闭事务外还会释放您可能拥有的所有锁.尽管从技术上讲,回滚也可以做到这一点,但是Commit总是比回滚更快.

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.

这篇关于对于便宜/快速的无写事务:COMMIT或ROLLBACK?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆