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


deadlocks and Stats


deadlocks and Stats

Author
Message
sqlguy80
sqlguy80
SSCommitted
SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)

Group: General Forum Members
Points: 1762 Visits: 390
Hi

I was getting alerts about deadlocks continuously every min on the server, I updated stats and alerts stopped. Again after two days, got deadlock alerts, updated stats, alerts gone.
did the trace (1222,-1), sent the deadlock victim details to development team.

What is the connection between stats and deadlocks?

Thanks
John Mitchell-245523
John Mitchell-245523
SSC Guru
SSC Guru (122K reputation)SSC Guru (122K reputation)SSC Guru (122K reputation)SSC Guru (122K reputation)SSC Guru (122K reputation)SSC Guru (122K reputation)SSC Guru (122K reputation)SSC Guru (122K reputation)

Group: General Forum Members
Points: 122934 Visits: 18761
If stats are out of date, the query optimizer is more likely to make a poor choice of execution plan. The query will take longer to run and deadlocks will become more likely. You'll want to have a look at the actual queries that are causing the deadlocks to see whether they can be tuned to make them more resilient to this situation.

John
Ivan R.
Ivan R.
SSC-Addicted
SSC-Addicted (460 reputation)SSC-Addicted (460 reputation)SSC-Addicted (460 reputation)SSC-Addicted (460 reputation)SSC-Addicted (460 reputation)SSC-Addicted (460 reputation)SSC-Addicted (460 reputation)SSC-Addicted (460 reputation)

Group: General Forum Members
Points: 460 Visits: 366
agree that the more time a query has to run, it increases the chance it could deadlock with something else. this might be the most generic correlation to deadlock.

on the other hand, reducing the time a query takes will generally be the way to reduce the chances of a deadlock.

hope this helps
ivan r.
Summer90
Summer90
One Orange Chip
One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)

Group: General Forum Members
Points: 26794 Visits: 4146

Review the query plan of the longer running queries and see if tuning indexes can help speed up the queries. Also, look into fragmentation of the tables as well. Maybe a rebuilding of the indexes if they get a high number of inserts, deletes and or updates to them causing fragmentation.


Subramaniam Chandrasekar
Subramaniam Chandrasekar
Hall of Fame
Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)

Group: General Forum Members
Points: 3128 Visits: 531
sqlguy80 - Wednesday, February 21, 2018 9:48 AM
Hi

I was getting alerts about deadlocks continuously every min on the server, I updated stats and alerts stopped. Again after two days, got deadlock alerts, updated stats, alerts gone.
did the trace (1222,-1), sent the deadlock victim details to development team.

What is the connection between stats and deadlocks?

Thanks

Could you check the cardinality estimator settings of your SQL Server ?

kevaburg
kevaburg
SSCoach
SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)SSCoach (15K reputation)

Group: General Forum Members
Points: 15218 Visits: 1280
Ivan R. - Sunday, February 25, 2018 7:21 PM
agree that the more time a query has to run, it increases the chance it could deadlock with something else. this might be the most generic correlation to deadlock.

on the other hand, reducing the time a query takes will generally be the way to reduce the chances of a deadlock.

hope this helps
ivan r.


Reducing the time a query takes to execute will not get rid of the deadlock issue. Deadlocks are a result of resource contention (very generally described) at runtime and can only be solved by programmatically altering the query to eliminate that contention. If you are experiencing Deadlocks as show by the trace flag then you need to hunt down the rpogrammtic cause for it.

What you are talking with regards to execution times are related to exclusive locks implemented during DML operations. You "could" resolve the issue by using a NOLOCK hint but this is definately not advisable because you could end up with inconsistent results due to the reading of, in end effect, inconsistent data. This is similat to having a database isolation level of Read Uncommitted.

Changing the isolation level to "Read Committed Snapshot" helps often by using versioning to reduce the problems associated with exclusive locking. You will need to be careful though because in some cases the version store could become bloated.
Ivan R.
Ivan R.
SSC-Addicted
SSC-Addicted (460 reputation)SSC-Addicted (460 reputation)SSC-Addicted (460 reputation)SSC-Addicted (460 reputation)SSC-Addicted (460 reputation)SSC-Addicted (460 reputation)SSC-Addicted (460 reputation)SSC-Addicted (460 reputation)

Group: General Forum Members
Points: 460 Visits: 366
kevaburg - Monday, March 5, 2018 10:34 AM
Ivan R. - Sunday, February 25, 2018 7:21 PM
agree that the more time a query has to run, it increases the chance it could deadlock with something else. this might be the most generic correlation to deadlock.

on the other hand, reducing the time a query takes will generally be the way to reduce the chances of a deadlock.

hope this helps
ivan r.


Reducing the time a query takes to execute will not get rid of the deadlock issue. Deadlocks are a result of resource contention (very generally described) at runtime and can only be solved by programmatically altering the query to eliminate that contention. If you are experiencing Deadlocks as show by the trace flag then you need to hunt down the rpogrammtic cause for it.

What you are talking with regards to execution times are related to exclusive locks implemented during DML operations. You "could" resolve the issue by using a NOLOCK hint but this is definately not advisable because you could end up with inconsistent results due to the reading of, in end effect, inconsistent data. This is similat to having a database isolation level of Read Uncommitted.

Changing the isolation level to "Read Committed Snapshot" helps often by using versioning to reduce the problems associated with exclusive locking. You will need to be careful though because in some cases the version store could become bloated.


Hi kevaburg -- Thanks for the reply. I agree with what you said. I'm very clear on what a deadlock and locking is and also read committed snapshot and why NOLOCK is not a good fix Smile Also keen on not giving bad advice as you are.

My response however was indeed very over simplified. I was mostly chiming in to what John Mitchell-245523 already said that poorly optimized queries (may it be to stale stats, lack of index, locking to many rows or tables unnecessarily) has a correlation to more deadlocks.

I was also citing along the lines of the official doco for minimizing deadlocks, which I think is a pretty good starting point: https://technet.microsoft.com/en-us/library/ms191242(v=sql.105).aspx



Lynn Pettis
Lynn Pettis
SSC Guru
SSC Guru (357K reputation)SSC Guru (357K reputation)SSC Guru (357K reputation)SSC Guru (357K reputation)SSC Guru (357K reputation)SSC Guru (357K reputation)SSC Guru (357K reputation)SSC Guru (357K reputation)

Group: General Forum Members
Points: 357740 Visits: 41695
And depending on the code it may also be worthwhile to set things up in an infinite loop with a break to exit when processing is done or an error other than a deadlock is encountered. I did this in some code I wrote, and in which I made sure it would be the deadlock victim if it was involved in a deadlock, so that the transaction aborted by the deadlock would be retried after a slight delay to allow the other code to finish.

Cool
Lynn Pettis

For better assistance in answering your questions, click here
For tips to get better help with Performance Problems, click here
For Running Totals and its variations, click here or when working with partitioned tables
For more about Tally Tables, click here
For more about Cross Tabs and Pivots, click here and here
Managing Transaction Logs

SQL Musings from the Desert Fountain Valley SQL (My Mirror Blog)
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