s1 t3:
_dexter@FAKE>update a set x=5 where x= 1 ;
s2 t4:
_dexter@FAKE>update b set x=5 where x=1 ;
s1 t5:
_dexter@FAKE>update a set x=5 where x= 1 ;
update aset x=5 where x= 1
*
ERROR atline 1:
ORA-00060:deadlock detected while waiting for resource
raise error00600 deadlock
_dexter@FAKE>select * from b ;
X
----------
3
2
s2 t6:
stillwaiting
直到s1 结束事务
|
|
Session1 |
Session2 |
Description |
| T1 |
update b set x=3 where x= 1 ; |
|
Session1 更新B表记录 |
| T2 |
|
_dexter@FAKE> update a set x=3 where x=1 ;
|
Session2更新A表记录 |
| T3 |
update a set x=5 where x= 1 ; waiting… |
|
Session1在事务中尝试修改Sessino2事务中修改的A表的数据 |
| T4 |
|
update b set x=5 where x=1 ; waiting… |
Session2在事务中尝试修改Sessino1事务中修改的B表的数据 |
| T5 |
ERROR at line 1: ORA-00060: deadlock detected while waiting for resource raise error 00600 deadlock |
|
上面的就是死锁的情况。Session1会Raise一个00060死锁的error。Sessino2 still waiting 。 |
从这里可以看到,由于逻辑错误锁引发的死锁。两个事务都在等待对方释放锁资源。
第一个争抢资源导致死锁的语句会被取消(只是取消这一个语句,而不是结束整个事务)