472,805 Members | 950 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,805 software developers and data experts.

stored procedure lock question



Hi there,

I have a newbie question regarding stored procedures and locking.
I'm trying to use a stored
procedure to perform a 'select for update' and return a cursor.
Below is a stripped down version
of the procedure:

CREATE PROCEDURE SELBTFLFORUPDATE()
LANGUAGE SQL
RESULT SETS 1
BEGIN
DECLARE C1 CURSOR WITH RETURN FOR
SELECT * FROM mfdp WHERE path = '/aNDERSNB/test/
file5'
FOR UPDATE;

OPEN C1;
END @
I'm able to access the cursor from the CLP or from my test CLI/ODBC
program, but the
locking isn't working like I would have thought. I have autocommit
off and have set my
isolation level to repeatable read for my clients. Yet, when I have
a client issue a call
to the stored procedure and then have another client issue a call
to the same procedure
before the first client has issued a commit, both calls to the
stored procedure complete.

In contrast, if I issue the 'select for update' command directly on
the client side
(e.g., with the CLP), the second 'select for update' hangs (as I
would expect) until the
first one is committed.

Am I doing something wrong here?

Thanks for any help,

Bill

Sep 18 '07 #1
5 6348
wi********************@gmail.com wrote:
On Sep 18, 11:21 am, Serge Rielau <srie...@ca.ibm.comwrote:

Serge,

Thanks for your reply.

As far as I can tell, even after I've fetched the rows (but
before closing the cursor or comitting the transaction),
the rows aren't locked. It almost seems like the 'FOR UPDATE'
clause when used in a stored procedure isn't locking rows
as it does when used in a CLI/ODBC statement or with
a CLP command.

When I explicitly use the 'FOR UPDATE' clause in my CLI program
and fetch the rows, they are locked at that point and another
client that tries to select the rows for update (when autocommit is
off and both clients have their isolation levels set to
repeatable read), hangs on its fetch call until the first one
commits
or rolls back.

When I use the 'FOR UPDATE' clause in a stored procedure
that the clients call, both sets of select and fetch calls return
before either has committed, suggesting that exclusive locks are
not being placed on the rows. Then, depending on the timing, I can
end up in a deadlock situation where one transaction is aborted
by DB2 due to the deadlock.
I'm not the one to claim user error easily, but that DB2 updates rows
without keeping an x-lock on it.... very unlikely.
Something in your story doesn't add up.

Cheers
Serge
--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
Sep 19 '07 #2


I'm probably not explaining the context very well, but
I did find that if I set the isolation level on the select
statement within the stored procedure (using the WITH
clause, e.g., "WITH RR" for repeatable read) that
everything works as expected.

Maybe the isolation level in stored procedures is not
necessarily the same as it is on the client side (e.g.,
just because it's set to RR on the client side may not
mean that it's enforced that way in a stored procedure
that's invoked by the client).

Anyway, thanks again for your comments.

Bill

I'm not the one to claim user error easily, but that DB2 updates rows
without keeping an x-lock on it.... very unlikely.
Something in your story doesn't add up.

Cheers
Serge
--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab

Sep 19 '07 #3
<wi********************@gmail.comwrote in message
news:11**********************@y27g2000pre.googlegr oups.com...
>

I'm probably not explaining the context very well, but
I did find that if I set the isolation level on the select
statement within the stored procedure (using the WITH
clause, e.g., "WITH RR" for repeatable read) that
everything works as expected.

Maybe the isolation level in stored procedures is not
necessarily the same as it is on the client side (e.g.,
just because it's set to RR on the client side may not
mean that it's enforced that way in a stored procedure
that's invoked by the client).

Anyway, thanks again for your comments.

Bill
Stored Procedures use static SQL which is bound into a package. The package
bind process has isolation level associated with it that has nothing to do
with the client.
Sep 19 '07 #4

Thanks for clarifying that. I mistakenly thought that the isolation
level
in a stored procedure would be the same as the level assigned to the
connection through which the call to the procedure is invoked.
>
Stored Procedures use static SQL which is bound into a package. The package
bind process has isolation level associated with it that has nothing to do
with the client.

Sep 19 '07 #5
<wi********************@gmail.comwrote in message
news:11*********************@i38g2000prf.googlegro ups.com...
>
Thanks for clarifying that. I mistakenly thought that the isolation
level
in a stored procedure would be the same as the level assigned to the
connection through which the call to the procedure is invoked.
The whole point of a stored procedure is that it runs on the server, not the
client. Since it uses static SQL by default, the access plan is pre-compiled
into a package.
Sep 19 '07 #6

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

Similar topics

2
by: metehan | last post by:
Hi all question regarding how transactions work in SQL Server... stored procedure below that generates unique IDs for messages we send to the backend It looks like sometimes, the number...
12
by: M Wells | last post by:
Hi All, I have a table that holds pregenerated member IDs. This table is used to assign an available member id to web site visitors who choose to register with the site So, conceptually the...
2
by: A.V.C. | last post by:
Hello, Can we lock stored procedure until its execution is complete ? I dont want 2 clients to simultenously execute the stored procedure in Sql Server 2000. My front end is ASP.net 1.0 ...
1
by: Alexander Korovyev | last post by:
hello, I have a bunch of stored procedures which are run for some background processing. In effect they are launched at random. At any given time point only one of the stored procedures is...
1
by: imarchenko | last post by:
Hello! I am trying to investigate strange problem with particular stored procedure. It runs OK for several days and suddenly we start getting and lot of locks. The reason being lock placed on...
2
by: scott | last post by:
Hi, Just wondering what sort of problems and advantages people have found using stored procedures. I have an app developed in VB6 & VB.NET and our developers are starting to re-write some of the...
1
by: Stu Lock | last post by:
Hi, I have converted some code to try and databind a datagrid using a stored procedure. Basically I am now naming the SP, setting the command type and adding and loading a prameter instead of...
3
by: Racerx | last post by:
Hi All: I use db2 v8 fp 14 on Aix. I am facing problems with a stored procedure that is causing a lot of locks and also goes in the lock wait state ending up hanging the application. Tried...
0
by: gregoryday | last post by:
I am having a problem with creating a stored procedure. The premise underwhich we are operating is the following: We are working with two tables. The first table simply stores an integer value...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
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=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth

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.