|
原帖由 Kamus 于 2007-12-12 01:38 发表
是有这个差异,在我的11g中同样是RX TM锁,我没有9i的数据库环境了,如果谁有帮忙测试一下在9i中的现象。
还有另外一个问题
lock table t1 in ROW SHARE MODE; --此时是RS TM锁
select * from t1 for update; -- 此时锁转换为RX TM,这是正常的
但是下面
lock table t1 in SHARE MODE; --此时是S TM锁
select * from t1 for update; -- 此时锁转换为SRX TM,实际上没有必要
看文档中的描述也没有说到后一种转换:
Default Locking for INSERT, UPDATE, DELETE, and SELECT ... FOR UPDATE
The locking characteristics of INSERT, UPDATE, DELETE, and SELECT ... FOR UPDATE statements are as follows:
* The transaction that contains a DML statement acquires exclusive row locks on the rows modified by the statement. Other transactions cannot update or delete the locked rows until the locking transaction either commits or rolls back.
* The transaction that contains a DML statement does not need to acquire row locks on any rows selected by a subquery or an implicit query, such as a query in a WHERE clause. A subquery or implicit query in a DML statement is guaranteed to be consistent as of the start of the query and does not see the effects of the DML statement it is part of.
* A query in a transaction can see the changes made by previous DML statements in the same transaction, but cannot see the changes of other transactions begun after its own transaction.
* In addition to the necessary exclusive row locks, a transaction that contains a DML statement acquires at least a row exclusive table lock on the table that contains the affected rows. If the containing transaction already holds a share, share row exclusive, or exclusive table lock for that table, the row exclusive table lock is not acquired. If the containing transaction already holds a row share table lock, Oracle automatically converts this lock to a row exclusive table lock.
9i的效果也是RX TM锁:
session 1:
SQL> select distinct sid from v$mystat;
SID
----------
37
session 2:
SQL> select * from v$lock where sid=37 and type in ('TM','TX');
no rows selected
session 1:
SQL> select * from t where a=1 for update;
A
----------
1
session 2:
SQL> /
ADDR KADDR SID TY ID1 ID2 LMODE REQUEST CTIME BLOCK
-------- -------- ---------- -- ---------- ---------- ---------- ---------- ---------- ----------
5D867808 5D867914 37 TX 1048582 113027 6 0 3 0
5D725A28 5D725A3C 37 TM 63338 0 3 0 3 0
根据这个文档上所说的,也不奇怪了。
If the containing transaction already holds a share, share rowexclusive, or exclusive table lock for that table, the row exclusivetable lock is not acquired. If the containing transaction already holdsa row share table lock, Oracle automatically converts this lock to arow exclusive table lock。
主要是锁提升的机制和锁转换的机制,我很不清楚,老大能不能解释一下 |
|