Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 SQL Server Locks?

Author  Topic 

xrum
Yak Posting Veteran

87 Posts

Posted - 2012-01-19 : 11:13:31
when i try to run an insert within an application, it hangs and eventually times out.

i ran the EXEC SP_WHO2 while it was still running and noticed that it was blocked by another process and there was a "lock" in the "wait type"

what does this mean? how do i fix it? i'm so lost.

the process that was in the "Blocked By" field had a simple select statement in it. i validated the statement and it works fine.

X002548
Not Just a Number

15586 Posts

Posted - 2012-01-19 : 11:15:25
what was the spid, who is running it, and what's it doing?

Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page

xrum
Yak Posting Veteran

87 Posts

Posted - 2012-01-19 : 11:40:46
please see screenshots attached:

process that is blocked is a simple delete stored procedure. it works if i run it byitself, outside of the application


process that blocks the above procedure, is a simple select count(*) function.


i'm so lost :(
Go to Top of Page

GilaMonster
Master Smack Fu Yak Hacker

4507 Posts

Posted - 2012-01-19 : 12:27:27
The select has locks on the data it is processing for the select and the update has to wait until the select is complete (data modifications needs exclusive locks)

Optimise the queries so that they run faster and hence have less chance to interfere with each other, or consider one of the snapshot isolation levels.

--
Gail Shaw
SQL Server MVP
Go to Top of Page

GilaMonster
Master Smack Fu Yak Hacker

4507 Posts

Posted - 2012-01-19 : 12:30:18
p.s. Chapter 6 [url]http://www.simple-talk.com/books/sql-books/troubleshooting-sql-server-a-guide-for-the-accidental-dba/[/url]

--
Gail Shaw
SQL Server MVP
Go to Top of Page

xrum
Yak Posting Veteran

87 Posts

Posted - 2012-01-19 : 13:41:50
quote:
Originally posted by GilaMonster

The select has locks on the data it is processing for the select and the update has to wait until the select is complete (data modifications needs exclusive locks)

Optimise the queries so that they run faster and hence have less chance to interfere with each other, or consider one of the snapshot isolation levels.

--
Gail Shaw
SQL Server MVP



but the query that locks up the process is just a simple
select count(*) from table1, where x="x"
there is no way for me to make it faster.

so confused :(
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2012-01-19 : 13:47:20
"there is no way for me to make it faster."

You sure?

What does

SET STATISTICS IO ON; SET STATISTICS TIME ON

select count(*) from table1, where x='x'

SET STATISTICS IO OFF; SET STATISTICS TIME OFF
GO

give you? (in particular the Scan Counts and the Logical I/O values)

And you could also look at the Actual Query Plan in SSMS and see if it recommends and indexes etc.
Go to Top of Page

Transact Charlie
Master Smack Fu Yak Hacker

3451 Posts

Posted - 2012-01-19 : 14:45:40
index on the column under consideration would improve that query immensely (assuming you don't have one).

You may want to try READ_COMMITTED_SNAPSHOT isolation level also (Gail mentioned changing the isolation level).

Charlie
===============================================================
Msg 3903, Level 16, State 1, Line 1736
The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION
Go to Top of Page

GilaMonster
Master Smack Fu Yak Hacker

4507 Posts

Posted - 2012-01-19 : 15:08:50
quote:
Originally posted by xrum

but the query that locks up the process is just a simple
select count(*) from table1, where x="x"
there is no way for me to make it faster.

so confused :(



Sure about that? You've got a nice small index on the column in the where clause and the data types match so that there's no implicit conversions and you have checked that the predicate is SARGable?

Did you take a look at chapter 6 of that book.

--
Gail Shaw
SQL Server MVP
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2012-01-19 : 16:30:04
[BOOOOOOOM]

Sargeable


[/BOOOOOOOM]

Heads just exploded

Search Arguable



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page
   

- Advertisement -