哪种并发控制是更有效的悲观或乐观并发控制 [英] which concurrency control is more efficient pessimistic or optimistic concurrency control

查看:45
本文介绍了哪种并发控制是更有效的悲观或乐观并发控制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道哪种并发控制更有效,是悲观还是乐观并发控制? SQL Server 2005使用悲观并发控制作为默认值是否有特殊原因?是出于与性能相关的原因吗?

I would like to know which concurrency control is more efficient, pessimistic or optimistic concurrency control? Is there a special reason why SQL Server 2005 uses pessimistic concurrency control as default? Is it for performance related reasons?

谢谢期待

推荐答案

我不确定 SQL Server 2005默认使用悲观并发控制是什么意思。 IMO SQL Server 2005为我们提供了一些工具,使我们能够自己实现乐观或悲观。我在简单对话中写了一些示例:开发生存并发的修改

I am not sure what do you mean by "SQL Server 2005 uses pessimistic concurrency control as default". IMO SQL Server 2005 provides us with tools that allow us to implement optimistic or pessimistic ourselves. I wrote a few examples on simple-talk: Developing Modifications that Survive Concurrency

编辑:我不认为SQL Server的默认行为完全是悲观并发控制。让我们考虑以下简单示例,该示例在默认隔离级别READ COMMITTED下运行:

I do not think that the default behavior of SQL Server is exactly "pessimistic concurrency control". Let us consider the following simple example, which runs under default isolation level, READ COMMITTED:

-- Connection one

BEGIN TRANSACTION;

SELECT * FROM Schedule 
WHERE ScheduledTime BETWEEN '20110624 06:30:00' 
AND '20110624 11:30' ;

-- Connection two
UPDATE Schedule 
SET Priority = 'High'
WHERE ScheduledTime ='20110624 08:45:00'
-- nothing prevent this update from completing, 
-- so this is not exactly pessimistic

-- Connection one
DELETE FROM Schedule 
WHERE ScheduledTime ='20110624 08:45:00' ;
COMMIT ;
-- nothing prevents us from deleting 
-- the modified row

这篇关于哪种并发控制是更有效的悲观或乐观并发控制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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