SELECT ...FOR UPDATE 与锁模式
执行SELECT ...FOR UPDATE语句时,其Orale是为其加的什么模式的锁及加锁的顺序是怎样的?
我在执行以上语句时,只要一执行就为其加了row exclusive模式锁(因为处理select ...for update 指定的行的其它DML(INSERT 除外)事务就排队等待而挂起),所示麻烦解释一下:
以下是oracle帮助说明(Oracle® Database Concepts 10g Release 2 (10.2) Part Number B14220-02):
assume that a transaction uses a SELECT statement with the FOR UPDATE clause to lock rows of a table. As a result, it acquires the exclusive row locks and a row share table lock for the table. If the transaction later updates one or more of the locked rows, the row share table lock is automatically converted to a row exclusive table lock.
同时在另一则帮助中Oracle如下描述:
Row Share Table Locks (RS)
A row share table lock (also sometimes called a subshare table lock, SS) indicates that the transaction holding the lock on the table has locked rows in the table and intends to update them. A row share table lock is automatically acquired for a table when one of the following SQL statements is run:
SELECT ... FROM table ... FOR UPDATE OF ... ; (这个我怎么也实现不了???)
LOCK TABLE table IN ROW SHARE MODE;
A row share table lock is the least restrictive mode of table lock, offering the highest degree of concurrency for a table.
Permitted Operations: A row share table lock held by a transaction allows other transactions to query, insert, update, delete, or lock rows concurrently in the same table. Therefore, other transactions can obtain simultaneous row share, row exclusive, share, and share row exclusive table locks for the same table.
Prohibited Operations: A row share table lock held by a transaction prevents other transactions from exclusive write access to the same table using only the following statement:
LOCK TABLE table IN EXCLUSIVE MODE;
|