Showing posts with label situation. Show all posts
Showing posts with label situation. Show all posts

Friday, March 30, 2012

ROWLOCK hint does not seem to have any effect

Hi
Here is the situation.
Many clients simulteneously update the same table, but *never*
the same rows. Each client has its *own* subset of rows.
So there is theoretically no concurrency problem.
Yet we are having locking issues.
We use ROWLOCK hint but it looks like it does not do anything.
Here is my simple test of it.
From one connection, I begin a transaction and update a record in a table
with the ROWLOCK hint.
Then I leave it as is
and
From another connection, I try to update a different record in the same
table also with the ROWLOCK hint.
Second command does not do anything until a transaction in the first
connection is commited.
If it is being locked by row, why is this happenning ?
Thanks
Alex
Hi
If SQL Server has to do a Table or Range Scan to get to data, the 2
operations may step on each other.
Correct indexing, espacially clustered indexes can help a lot.
Post DML and DDL so that we can look at it.
Mike Epprecht, Microsoft SQL Server MVP
Zurich, Switzerland
MVP Program: http://www.microsoft.com/mvp
Blog: http://www.msmvps.com/epprecht/
"Alex" wrote:

> Hi
> Here is the situation.
> Many clients simulteneously update the same table, but *never*
> the same rows. Each client has its *own* subset of rows.
> So there is theoretically no concurrency problem.
> Yet we are having locking issues.
> We use ROWLOCK hint but it looks like it does not do anything.
> Here is my simple test of it.
> From one connection, I begin a transaction and update a record in a table
> with the ROWLOCK hint.
> Then I leave it as is
> and
> From another connection, I try to update a different record in the same
> table also with the ROWLOCK hint.
> Second command does not do anything until a transaction in the first
> connection is commited.
> If it is being locked by row, why is this happenning ?
> Thanks
> Alex
>
>
>
sql

ROWLOCK hint does not seem to do anything

Hi
Here is the situation.
Hi
Here is the situation.
Many clients simulteneously update the same table, but *never*
the same rows. Each client has its *own* subset of rows.
So there is theoretically no concurrency problem.
Yet we are having locking issues.
We use ROWLOCK hint but it looks like it does not do anything.
Here is my simple test of it.
From one connection, I begin a transaction and update a record in a table
with the ROWLOCK hint.
Then I leave it as is
and
From another connection, I try to update a different record in the same
table also with the ROWLOCK hint.
Second command does not do anything until a transaction in the first
connection is commited.
If it is being locked by row, why is this happenning ?
Thanks
AlexAlex
SQL Server will assign ROWLOCK by default
Read Vyas's article describing row level security
http://vyaskn.tripod.com/ row_level...as
es.htm
"Alex" <alex@.nospam.com> wrote in message
news:d6edfg$cmc$1@.lust.ihug.co.nz...
> Hi
> Here is the situation.
> Hi
> Here is the situation.
> Many clients simulteneously update the same table, but *never*
> the same rows. Each client has its *own* subset of rows.
> So there is theoretically no concurrency problem.
> Yet we are having locking issues.
> We use ROWLOCK hint but it looks like it does not do anything.
> Here is my simple test of it.
> From one connection, I begin a transaction and update a record in a table
> with the ROWLOCK hint.
> Then I leave it as is
> and
> From another connection, I try to update a different record in the same
> table also with the ROWLOCK hint.
> Second command does not do anything until a transaction in the first
> connection is commited.
> If it is being locked by row, why is this happenning ?
> Thanks
> Alex
>
>
>|||On Wed, 18 May 2005 13:40:34 +1000, Alex wrote:
(snip)
>From one connection, I begin a transaction and update a record in a table
>with the ROWLOCK hint.
>Then I leave it as is
>and
>From another connection, I try to update a different record in the same
>table also with the ROWLOCK hint.
Hi Alex,
Do you have a PRIMARY KEY, UNIQUE or other INDEX on this table? Is the
WHERE clause such that this index can be used to find the row to be
updated by the seecond statement?
If the answer to either of these is "no", then SQL Server has to scan
the whole table for the UPDATE. And it will encounter the locked row
during that process. Repeat the experiment, but with the option to show
execution plan set on. After issuing commit or rollback in the first
connection, the second should finish; now you can check the execution
plan.
Also, if the indexed column itself is changed by the first UPDATE
statement, there will be a lock on that index page as well. This can
also cause a wwait in your second query, if that index is used in the
execution plan.
For more detailed info, more information is definitely needed. A repro
script (CREATE TABLE statements, INSERT statements and the statments you
executed on the two connections) would be ideal. See
www.aspfaq.com/5006.
Best, Hugo
--
(Remove _NO_ and _SPAM_ to get my e-mail address)

Wednesday, March 21, 2012

Row lock versus Page lock in SQL 2000.

Hi
We are facing an acute situation in our web-application. Technology is ASP.NEt/VB.NET, SQL Server 2000.

Consider a scenario in which User 1 is clicking on a button which calls a SQL stored procedure. This procedure selects Group A of records of Database Page1.

At the same time if User 2 also clicks the same button which calls same SQL stored procedure. This procedure selects Group B of records of Database Page1.

So, its the same Page1 but different sets of records. At this moment, both the calls have shared locked on the Page1 inside the procedure.

Now, in call 1, inside the procedure after selecting Group A of records, the next statement is and update to those records. As soon as update statement executes, SQL Server throws a deadlock exception as follows :

Transaction (Process ID 78) was deadlocked on lock resources with another process and has been chosen as the deadlock victim. Rerun the transaction

We are able to understand why its happening. Its because, Group A and Group B of records are on the same Page1. But both the users have shared lock on the Page1. So, no one gets the exclusive lock in records for update, even though, the records are different.

How can I resolve this issue? How can I get lock on wanted rows instead of entire page?

Please advice. Thanks a bunch.

PankajWhy are you implementing *read* locks? Concurrent access via pessimistic locking is very low. Try implementing optimistic locking.

If you absolutely cannot implement optimistic locking (think 3 times about this before deciding on pessimistic locking), then you can make it so user 2 doesn't get to see the records at all and instead gets a message saying try back later.sql