Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I be a deadlock victim if I'm not executing a query within a transaction?

Tags:

Lets say I open a transaction and run update queries.

BEGIN TRANSACTION
UPDATE x SET y = z WHERE w = v

The query returns successfully and the transaction stays open deliberately for a period of time before I decide to commit.

While I'm sitting on the transaction is it ever possible the MSSQL deadlock machinary would be able to preempt my open transaction that is not actually executing anything to either clear a deadlock or free resources as system memory/resource limits are reached?

I know about SET DEADLOCK_PRIORITY and have read the MSDN articles on the topic of deadlocks. Logically since I'm not actively seeking to stake claim on any additional resources I can't imagine a scenario that would trigger a sane deadlock avoidance algorithm.

Does anyone know for sure if its possible that simply holding any locks can make me a valid target? Similarly could any low resource condition trigger the killing of my SPID?

like image 727
Einstein Avatar asked Jan 13 '10 07:01

Einstein


1 Answers

NO

For a deadlock to occur all the participants in the deadlock chain must be waiting for a resource (a lock). If your connection is idle it means it doesn't execute a request, which implies it cannot be waiting.

As for other conditions that can kill your session I can think of at least three:

  • administrative operations that use WITH ROLLBACK_IMMEDIATE
  • a mirroring failover
  • intentional KILL <yourspid>, perhaps as a joke by your friendly DBA
like image 163
Remus Rusanu Avatar answered Sep 30 '22 02:09

Remus Rusanu