Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How are SQL Server Intent-locks work?

I have read some articles regarding intent lock that there are plenty of intent locks which are Intent shared (IS), Intent exclusive (IX), Shared with intent exclusive (SIX), Intent update (IU), Shared intent update (SIU), Update intent exclusive (UIX). Sometimes I found these locks on the lock statistics and I have trouble to identify each of these locks because sometimes there are number of performance issues occured

What are intent lock actually used for? how does each of those intent locks work against each other locks in database concurrency?

thank you

like image 394
Alfin E. R. Avatar asked May 02 '18 11:05

Alfin E. R.


2 Answers

Intent locks are a performance enhancement that allows SQL Server to quickly check for locks at a more granular level.

https://www.sqlpassion.at/archive/2016/05/16/why-do-we-need-intent-locks-in-sql-server/

like image 104
MJH Avatar answered Sep 27 '22 22:09

MJH


I have got some more information as well regarding this matter.

Intent shared (IS) With this lock mode, SQL Server protects requested or acquired shared (S) locks on some resources lower in the lock hierarchy.

Intent exclusive (IX) This lock mode is a superset of intent shared (IS) locks that not only protects locks on resources lower in the hierarchy, but also protects requested or acquired exclusive (X) locks on some resources lower in the hierarchy.

Shared with intent exclusive (SIX) This lock mode protects requested or acquired shared (S) locks on all resources lower in the hierarchy and intent exclusive (IX) locks on some resources lower in the hierarchy. Only one shared with intent exclusive (SIX) lock can exist at a time for a resource to prevent other transactions from modifying it. However, lower level resources can have intent shared (IS) locks and can be read by other transactions.

Intent update (IU) SQL Server uses this lock mode on page resources only to protect requested or acquired update (U) locks on all lower-level resources and converts it to an intent exclusive (IX) lock if a transaction performs an update operation.

Shared intent update (SIU) This lock mode is a combination of shared (S) and intent update (IU) locks and occurs when a transaction acquires each lock separately but holds them at the same time.

Update intent exclusive (UIX) This lock mode results from a combination of update (U) and intent exclusive (IX) locks that a transaction acquires separately but holds at the same time.

like image 21
Alfin E. R. Avatar answered Sep 28 '22 00:09

Alfin E. R.