473,508 Members | 2,249 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

reading DB2 with isolation CS - why is the lock blocking?

Dealing with the Oracle / DB2 XA (2-phase commit) drivers, I found a
locking situation in DB2 I do not understand. It is actually a pretty
simple scenario to which I can drill it down.

Let say I have a table with one column. This table contains 2 rows:
select * from my_tab
test1
test2

Now I insert a value (with a 1st CLP): insert into my_tab values('x1')

When I try to read the table from a 2nd CLP with isolation level CS
(read committed) it hangs. It waits because of the lock of the row
insert:
select * from my_tab with CS -- hangs

I would expect - like in Oracle - that with CS isolation it would
simply give me the 2 rows (test1/2) above.
select * from my_tab with UR -- does not hang and already displays x1,
AS EXPECTED
select * from my my_tab where col < 'x' with CS -- hangs if I do not
have an index on col, does not hang if I have an index on col

I find this pretty strange for isolation CS: As a conclusion an
insert/update of a table could lock all other select * until it is
committed.

Do I miss something here?
Regards HW

Nov 12 '05 #1
4 8495

<un***@web.de> wrote in message
news:11**********************@g49g2000cwa.googlegr oups.com...
Dealing with the Oracle / DB2 XA (2-phase commit) drivers, I found a
locking situation in DB2 I do not understand. It is actually a pretty
simple scenario to which I can drill it down.

Let say I have a table with one column. This table contains 2 rows:
select * from my_tab
test1
test2

Now I insert a value (with a 1st CLP): insert into my_tab values('x1')

When I try to read the table from a 2nd CLP with isolation level CS
(read committed) it hangs. It waits because of the lock of the row
insert:
select * from my_tab with CS -- hangs

I would expect - like in Oracle - that with CS isolation it would
simply give me the 2 rows (test1/2) above.
select * from my_tab with UR -- does not hang and already displays x1,
AS EXPECTED
select * from my my_tab where col < 'x' with CS -- hangs if I do not
have an index on col, does not hang if I have an index on col

I find this pretty strange for isolation CS: As a conclusion an
insert/update of a table could lock all other select * until it is
committed.

Do I miss something here?


No, aside from the fact that DB2 is not Oracle, and things do not
neccessarily work exactly the same.

DB2 uses next-key locking to ensure that the result set remains constant.
(CS = cursor stability in DB2 parlance.) In the presence of indexes, this
can block other queries from completing until the original query commits.

--
Matt Emmerton
Nov 12 '05 #2
<un***@web.de> wrote in message
news:11**********************@g49g2000cwa.googlegr oups.com...
Dealing with the Oracle / DB2 XA (2-phase commit) drivers, I found a
locking situation in DB2 I do not understand. It is actually a pretty
simple scenario to which I can drill it down.

Let say I have a table with one column. This table contains 2 rows:
select * from my_tab
test1
test2

Now I insert a value (with a 1st CLP): insert into my_tab values('x1')

When I try to read the table from a 2nd CLP with isolation level CS
(read committed) it hangs. It waits because of the lock of the row
insert:
select * from my_tab with CS -- hangs

I would expect - like in Oracle - that with CS isolation it would
simply give me the 2 rows (test1/2) above.
select * from my_tab with UR -- does not hang and already displays x1,
AS EXPECTED
select * from my my_tab where col < 'x' with CS -- hangs if I do not
have an index on col, does not hang if I have an index on col

I find this pretty strange for isolation CS: As a conclusion an
insert/update of a table could lock all other select * until it is
committed.

Do I miss something here?
Regards HW


In Oracle, each user is guaranteed read constancy of the data (albeit the
old data), if someone has else has updated it and not committed. Oracle must
temporarily create and store a separate copy of the data to do this, so it
is not "free" from a performance perspective.

DB2 has a significantly different locking architecture than Oracle, and does
not provide read consistency of updated data (ability to see the data before
it was changed for uncommitted updates).

However, there are some new DB2 environment (registry) variables that allow
DB2 to have some of the benefits of Oracle optimistic locking, without the
extra overhead:

You can use the DB2_SKIPINSERTED registry variable to skip uncommitted
inserted rows for Cursor Stability (CS) and Read Stability (RS) isolation
levels. Having this registry variable set ON produces greater concurrency
and would therefore be the preferred choice for most applications (and
emulates how Oracle would function).

The registry variables DB2_SKIPDELETED and DB2_EVALUNCOMMITTED are used to
skip (not wait on the lock) uncommitted deletions and uncommitted updates.
In the case of DB2_EVALUNCOMMITTED, DB2 will skip updated rows that no
longer qualify the predicate criteria in the query. Otherwise, CS and RS
isolation levels require the processing of committed data only.

Registry variables are changed with the DB2SET command and are in effect at
the instance level.

The DB2_SKIPINSERTED was introduced in FP9 (8.2.2) and the others I believe
were included in FP4 (but I am not going to look it up and I provide no
guarantees about the fixpack level needed).
Nov 12 '05 #3
Thanks a lot for these answers.
They contain some very helpful hints for me!

Best regards
HW

Nov 12 '05 #4
un***@web.de wrote:
Dealing with the Oracle / DB2 XA (2-phase commit) drivers, I found a
locking situation in DB2 I do not understand. It is actually a pretty
simple scenario to which I can drill it down.

Let say I have a table with one column. This table contains 2 rows:
select * from my_tab
test1
test2

Now I insert a value (with a 1st CLP): insert into my_tab values('x1')

When I try to read the table from a 2nd CLP with isolation level CS
(read committed) it hangs.
It waits because of the lock of the row
insert:
select * from my_tab with CS -- hangs

I would expect - like in Oracle - that with CS isolation it would
simply give me the 2 rows (test1/2) above.

No, by default DB@ tries to catch that third row. So it has to wait.
For insert however there is no difference for correctness, so DB2
supplies the DB2_SKIP_INSERTED registry variables.
http://publib.boulder.ibm.com/infoce...n/c0012389.htm

There is another registry variable you can set to skip uncommited rows
which do not qualify base predicates. That one is semantically a bit
risky though.

Cheers
Serge
--
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab
Nov 12 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
14868
by: Eddie | last post by:
I wondering which one of the following I should use to get the best performance. 1. "SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED" OR 2. "WITH (NOLOCK)" I notice that when I use the #1...
3
2750
by: Wolfgang Bachmann | last post by:
We migrated a database from Version 5.1 to 8.1 and are experiencing massive locking problems. We migrated in the following steps: 0) Server 5.2, Clients 5.2: everithing was fine 1) Server 5.2,...
3
4598
by: joshsackett | last post by:
I am redesigning an application that distributes heldesk tickets to our 50 engineers automatically. When the engineer logs into their window a stored procedure executes that searches through all...
0
1382
by: nielsgron | last post by:
Hi, I am trying to find a way to query for the (lock) blocking connection on my DB2 server. I am using DB2 for LUW 8.1 and 8.2. I have two connections, one which has an exclusive lock, and the...
3
7202
by: D. | last post by:
I have a question about the "readCommitted" transaction isolation level. I have a client that is updating a record on a table. I suspend the execution after the UPDATE but before the commit...
1
1959
by: Arun Srinivasan | last post by:
I am just confused because of the following scenario. * I have turned on the new 8.2 registry variables skipdeleted, skipinserted, evaluncommitted to ON * I gave a select * from <>, it was...
5
13507
by: sticky | last post by:
Hi I need to be able to lock a table against INSERT and UPDATE, but not SELECT, for the duration of a transaction. The transaction will be defined at the application level in c#, and then use...
4
1802
by: quincy451 | last post by:
I am running MS SQL 2000 server. The table involved is only about 10,000 records. But this is the behavior I am seeing. The local machine is querying the table looking for a particular record....
4
6304
by: Mateusz Mrozewski | last post by:
Hi, Is there a difference between: SELECT * FROM mytable WHERE somecolumn='Y' FOR UPDATE WITH RS and SELECT * FROM mytable WHERE somecolumn='Y' FOR UPDATE WITH RS USE AND KEEP UPDATE LOCKS I...
0
7225
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7326
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7383
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7498
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5053
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4707
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3194
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3182
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
418
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.