If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > locking problem with update ... where ... in (select...)

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-18-04, 05:48
jmychung jmychung is offline
Registered User
 
Join Date: Oct 2003
Location: Hong Kong
Posts: 41
Question locking problem with update ... where ... in (select...)

Hi,

I have a locking problem with the following scenario:

session 0:
create table test1 (col1 bigint, col2 char(10));
insert into test1 values (1, '1');
insert into test1 values (2, '2');
commit
* col1 is the primary key

session 1:
update test1 set col2 = '9' where col1 in (select col1 from test1 where col1 = 1)

session 2:
update test1 set col2 = '9' where col1 in (select col1 from test1 where col1 = 2)

session 2 has to wait session 1 to commit. However, session 1 and session 2 are updating different record. How can I prevent session 1 from locking records that it is not actually updating?

Can anyone help me? Thanks in advance.
Reply With Quote
  #2 (permalink)  
Old 08-18-04, 07:09
hurmavi hurmavi is offline
Registered User
 
Join Date: Jan 2004
Location: Europe, Finland, Helsinki
Posts: 60
One thing: you dont seem to have no indexes. So those update sessions are making a table space scan. And doing so, both sessions will lock whole table.

Cherrs, Bill
Reply With Quote
  #3 (permalink)  
Old 08-18-04, 09:44
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
You should also rewrite your update statements to:

session 1:
update test1 set col2 = '9' where col1 = 1

session 2:
update test1 set col2 = '9' where col1 = 2


Andy
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On