开发者

which concurrency control is more efficient pessimistic or optimistic concurrency control

I w开发者_C百科ould 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?

Thanks in anticipation


This depends entirely on what concurrency needs your application has. If you are developing an OLTP app, pessiimistic would probably be best... If you are developing a single-user database, optimistic is fine.


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

Edit: 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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜