472,958 Members | 2,541 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,958 software developers and data experts.

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 8440

<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
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
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
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
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
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
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
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
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
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
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
2
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.