SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Deadlock investigation, help!


Deadlock investigation, help!

Author
Message
Paul White
Paul White
SSC-Dedicated
SSC-Dedicated (34K reputation)SSC-Dedicated (34K reputation)SSC-Dedicated (34K reputation)SSC-Dedicated (34K reputation)SSC-Dedicated (34K reputation)SSC-Dedicated (34K reputation)SSC-Dedicated (34K reputation)SSC-Dedicated (34K reputation)

Group: General Forum Members
Points: 34422 Visits: 11359
msandico 57892 (8/30/2012)
we never REBUILD because of the requirement of the system to stay UP all the time

REBUILD supports the ONLINE option. I presume you have Enterprise Edition and are using the ONLINE option already when adding indexes.

we REORGANIZE weekly but on a heap table, i believe the non-clustered indexes will still be fragmented

ALTER INDEX ... REORGANIZE allows you to specify ALL indexes or individual ones. Both ALTER INDEX ALL and ALTER TABLE REBUILD affect the heap and all non-clustered indexes, as far as I recall.

I also thought about giving a row locking hint (PAGLOCK) not (TABLOCK), because in the graph isn't it trying to lock the table to do the changes? My theory is that if the INSERT and UPDATE does a PAGLOCK then maybe a deadlock won't occur because the processes are locking at the page level rather than the table level..thus reducing the chance of wanting each other's resources...does that even make sense?

That's the broad theory of it, yes.

I barely have access to the code as the app that's sending the queries is developed by a third-party..but i have rare access to them if absolutley needed..just wondering if this can be fixed at the server side before going to client side..

Not that I know of. We can't use a plan guide to specify a lock-granularity hint for the table using the TABLE HINT syntax because it affects the semantic of the query (you get error 8722 if you try this).



Paul White
SQLPerformance.com
SQLblog.com
@SQL_Kiwi
msandico 57892
msandico 57892
SSC-Enthusiastic
SSC-Enthusiastic (195 reputation)SSC-Enthusiastic (195 reputation)SSC-Enthusiastic (195 reputation)SSC-Enthusiastic (195 reputation)SSC-Enthusiastic (195 reputation)SSC-Enthusiastic (195 reputation)SSC-Enthusiastic (195 reputation)SSC-Enthusiastic (195 reputation)

Group: General Forum Members
Points: 195 Visits: 195
Hi All,

Just to finish this off, thanks for all the help again.

I figured out that it was a missing clustered index and defragmentation (or fragmentation, whichever way you look at it, i think specifically data fragmentation), that was the culprit.

From the graph, my theory was that 2 ad hoc INSERT processes were trying to insert into the table. For some reason, since it was a heap, it was trying to escalate it's lock (i'm assuming at the page level), to a table level lock. Since the two processes occurred within milliseconds of each other, it each grabbed a page, and were both trying to escalate to a table-level lock.....hence, DEADLOCK.

With the clustered index, i was hoping that it grabbed a page-level lock (or something more granular than a table-level lock), and the lock was held quicker b/c SQL knew exactly where to insert the row. and thus prevent a deadlock..

Hopefully that reasoning made sense..from a technical persepctive.
msandico 57892
msandico 57892
SSC-Enthusiastic
SSC-Enthusiastic (195 reputation)SSC-Enthusiastic (195 reputation)SSC-Enthusiastic (195 reputation)SSC-Enthusiastic (195 reputation)SSC-Enthusiastic (195 reputation)SSC-Enthusiastic (195 reputation)SSC-Enthusiastic (195 reputation)SSC-Enthusiastic (195 reputation)

Group: General Forum Members
Points: 195 Visits: 195
Hi All,

Just to finish this off, thanks for all the help again.

I figured out that it was a missing clustered index and defragmentation (or fragmentation, whichever way you look at it, i think specifically data fragmentation), that was the culprit.

From the graph, my theory was that 2 ad hoc INSERT processes were trying to insert into the table. For some reason, since it was a heap, it was trying to escalate it's lock (i'm assuming at the page level), to a table level lock. Since the two processes occurred within milliseconds of each other, it each grabbed a page, and were both trying to escalate to a table-level lock.....hence, DEADLOCK.

With the clustered index, i was hoping that it grabbed a page-level lock (or something more granular than a table-level lock), and the lock was held quicker b/c SQL knew exactly where to insert the row. and thus prevent a deadlock..

Hopefully that reasoning made sense..from a technical persepctive.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search