Unix Technical Forum

Select Insert Deadlock

This is a discussion on Select Insert Deadlock within the SQL Server forums, part of the Microsoft SQL Server category; --> Lets say we select from TableA that joins to TableB TableB also gets data inserted into into it via ...


Go Back   Unix Technical Forum > Database Server Software > Microsoft SQL Server > SQL Server

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 09-12-2008, 05:23 PM
bozzzza
 
Posts: n/a
Default Select Insert Deadlock

Lets say we select from TableA that joins to TableB

TableB also gets data inserted into into it via another query.

So I guess SQL server places a shared lock on Table A and Table B.
and the insert will try and put an exclusive lock on the table.

We then get a deadlock. What I am trying to get my head around is why?
I would have thought that the Insert query would wait until the lock
was released on table B. Ok the select query does take a long time,
but I would have thought the insert would time out.

I know there is something I am missing in my logic. I am just trying
to figure out how the tables become deadlocked in this situation.

TIA

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 09-12-2008, 05:23 PM
Erland Sommarskog
 
Posts: n/a
Default Re: Select Insert Deadlock

bozzzza (bozzzza@googlemail.com) writes:
> Lets say we select from TableA that joins to TableB
>
> TableB also gets data inserted into into it via another query.
>
> So I guess SQL server places a shared lock on Table A and Table B.
> and the insert will try and put an exclusive lock on the table.
>
> We then get a deadlock. What I am trying to get my head around is why?
> I would have thought that the Insert query would wait until the lock
> was released on table B. Ok the select query does take a long time,
> but I would have thought the insert would time out.


Without seeing the queries and the query plans, the field is open for
wild speculations.

But to start with, locks are far from always on table level. Most commonly
locks are on row level, or key level in case of an index.

I would guess the problem has to do with index and data pages being
access in different order.


--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Links for SQL Server Books Online:
SQL 2008: http://msdn.microsoft.com/en-us/sqlserver/cc514207.aspx
SQL 2005: http://msdn.microsoft.com/en-us/sqlserver/bb895970.aspx
SQL 2000: http://www.microsoft.com/sql/prodinf...ons/books.mspx

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads for: Select Insert Deadlock

Thread Thread Starter Forum Replies Last Post
DEADLOCK INSERT Ricardo Durao pgsql Admins 0 04-10-2008 05:54 AM
insert deadlock Brian Cox Pgsql General 2 04-09-2008 08:19 AM
Deadlock within select? jw_guildford@yahoo.co.uk SQL Server 2 02-29-2008 07:20 PM
Parellel insert causes deadlock Prakash DB2 3 02-26-2008 03:40 PM
Oracle 8i Deadlock without deadlock graph on insert statement vdemers@gmail.com Oracle Database 0 02-26-2008 08:10 AM


All times are GMT. The time now is 05:03 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
www.UnixAdminTalk.com