简体   繁体   English

Oracle中的并发更新:是否锁定?

[英]Concurrent Updates in Oracle: Locking or not?

I'm confused. 我糊涂了。 I'm reading about MVCC in Oracle. 我正在读Oracle中的MVCC。 I thought MVCC meant no locks. 我以为MVCC意味着没有锁。 But, I read somewhere else that all UPDATE s do automatic locking, regardless of the isolation level. 但是,我在其他地方读到所有UPDATE都自动锁定,无论隔离级别如何。 Can someone explain what happens during an Oracle update? 有人可以解释Oracle更新期间会发生什么吗? And what happens when multiple read committed transactions try to do a concurrent update t set c = c + 1 where id = 3 . 当多个读取提交的事务尝试进行并发update t set c = c + 1 where id = 3时,会发生什么? update t set c = c + 1 where id = 3 What's the result, given c = 1 before either of the transactions, and what's going on with the locks and SCN? 结果是什么,在任何一个交易之前给定c = 1,以及锁和SCN发生了什么?

Begin T1
Begin T2
T1:  update t set c = c + 1 where id = 3
T2:  update t set c = c + 1 where id = 3
Commit T1
Commit T2

You're right, this will lock the row regardless of the isolation level. 你没错,无论隔离级别如何,都会锁定行。 With MVCC you can get consistent reads with no locks, but you still need locks when writing. 使用MVCC,您可以在没有锁的情况下获得一致的读取,但在写入时仍需要锁定。

The second transaction will wait for the first one to finish (eg: COMMIT or ROLLBACK ) before attempting to do anything. 在尝试执行任何操作之前,第二个事务将等待第一个事务完成(例如: COMMITROLLBACK )。 So in this case the cursor on T2 would "hang" on the update, waiting for T1 to finish. 因此,在这种情况下,T2上的光标将“挂起”在更新上,等待T1完成。

You'll get a new SCN after T1 commits and another after T2 commits. 你会在T1提交后获得一个新的SCN,在T2提交后获得另一个SCN。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM