Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> Re: q: diffrence between row_shared and row_exclusive lock ?
Hi Ted,
You need to check the doco more carefully. See my comments imbedded.
"Ted Chyn" <tedchyn_at_yahoo.com> wrote in message
news:44a19320.0207210854.2e923d2c_at_posting.google.com...
> "Richard Foote" <richard.foote_at_bigpond.com> wrote in message
news:<jqt_8.40123$Hj3.120006_at_newsfeeds.bigpond.com>...
> > Hi Ted,
> >
> > OK, we need to separate "Row Level" locks from "Table Level" locks. A
row
> > can be either be locked or shared. If locked, no other session may lock
*the
> > same row*. If shared, then it may be locked by any session. When
performing
> > such an operation (such as DML, or select for update, or update of
primary
> > key, or delete cascade), these operations *also* lock the *TABLE* in one
of
> > a number of different modes (as previously mentioned). It's these table
> > locks that have varying degrees of restriction and can be implemented by
> > manually locking a table.
> >
> #########################################################################
> > For example, in one session issue a 'lock table emp in row share mode'.
This
> > locks the *whole table* in share row mode (which is the least
restrictive
> > lock). In another session, issue another 'lock table emp in row share
mode'
> > and it *will* work. But issue a 'lock table emp in exclusive mode' and
this
> > will *NOT* work. This other session is locked out (until the commit)
because
> > a row share table lock locks out exclusive table locks. In fact.
exclusive
> > table locks is the only lock that a row share lock prevents. Get it ?
> #######################################################################
> richard, If row share locked out row exlusive,
> then how do you explain following
> 1. case #1
> where one sid has tm lmode =2 and another sid can obtain another
> tm lock lmode=3 on the same table.
> 2. case #2
> where one sid has tm lmode=3 and another sid can obtain another
> tm lock lmode=3 on the same table.
OK, a Row Share Lock (SS mode 2) *DOES NOT* lock out a Row Exclusive lock (SX mode 3) as previously stated. A Row Share lock *ONLY* locks out an Exclusive Table Lock (X mode 6) as well as use row locks to lock the individual rows if the lock was obtained with a select for update.
You *are* permitted to perform DML on the same table and obtain a Row Exclusive *table* lock but you are not permitted to lock the individual rows if they've been previously locked.
That's the difference between table and row locks.
>
> >
> #1
> ADDR KADDR SID TY ID1 ID2 LMODE
REQUEST
> >
> In #1 sid 9 (select .. for update). tm lock lmode=2
> another session (sid=10) I can lock the same table with row
exclusive
> (lmode =3). in both cases id1 = 30139
>
Same scenario as above. You are permitted to lock the *table* in Row Share Mode 2 *and* lock the *table* in Row Exclusive Mode !! You just can't lock the individual rows concurrently.
> #2
>
> ADDR KADDR SID TY ID1 ID2 LMODE
REQUEST
> -------- -------- ---------- -- ---------- ---------- ---------- ---------
-
> CTIME BLOCK
> ---------- ----------
> 6BB4E074 6BB4E088 9 TM 30139 0 3
0
> 65 0
>
> 6BB4E0F8 6BB4E10C 10 TM 30139 0 3
0
> 30 0
>
> In #2 sid=9 lock table(30139) in row exclusive mode (lmode=3)
> sid=10 can lock the same table(30139) with row exclusive
mode(lmode=3) >
Let me summarise the doco for you.
Row Share Table Locks (SS mode 2) locks out Exclusive Table locks (X mode 5).
Row Exclusive Table Locks (SX mode 3) locks out Share Table locks (S mode 4) and Share Row Exclusive Table locks (SSX mode 5) and Exclusive Table locks (X mode 6).
Share Table Locks (S mode 4) locks out Row Exclusive Table locks (SX mode 3) and Share Row Exclusive Table locks (SSX mode 5) and Exclusive Table locks (X mode 6).
Shared Row Exclusive locks (SSX mode 5) locks out Row Exclusive Locks (SX mode 3) and Share Table locks (S mode 4) and Share Row Exclusive Table locks (SSX mode 5) and Exclusive Table locks (X mode 6).
Exclusive Table locks (X mode 6) locks out all other table locks (mode 2, 3, 4, 5 and 6).
An individual row can be either in be shared mode (and have no locks) or in locked mode (Row Exclusive TX) in which case no other process can share this row level lock. Note DML, select for update, etc. take *two* types of locks, row locks on the corresponding rows being processed and corresponding table locks depending on the operation.
Phew !!
Please re-read the doco on locks and be clear on the distinction between row level and table level locks and what are the restrictions on each type of lock.
I hope this helps.
Regards
Richard
> > > > >