Why does this RX-X lock not appear in Extended Events?Is there a more helpful way to detect lock...
2 weeks and a tight budget to prepare for Z-day. How long can I hunker down?
Exploiting the delay when a festival ticket is scanned
Did the Americans trade destroyers in the "destroyer deal" that they would later need themselves?
Introducing Tetronogram!
Is it possible to attain stream-entry if one is only following "the 5 precepts"?
Can a black hole formation be stopped or interrupted
If an arcane trickster rogue uses his mage hand and makes it invisible, does that mean anything the hand picks up is also invisible?
Are there attacks that are neither melee nor ranged?
How can Paypal know my card is being used in another account?
Does Dispel Magic destroy Artificer Turrets?
What is more environmentally friendly? An A320 or a car?
Does dual boot harm a laptop battery or reduce its life?
This day in history III
Composing fill in the blanks
Sci-fi change: Too much or Not enough
Why would anyone ever invest in a cash-only etf?
Why is it considered acid rain with pH <5.6?
Why does the Eurostar not show youth pricing?
Why force the nose of 737 Max down in the first place?
What language is Raven using for her attack in the new 52?
What steps would an amateur scientist have to take in order to get a scientific breakthrough published?
What is the most efficient way to write 'for' loops in Matlab?
Is there an antonym(a complementary antonym) for "spicy" or "hot" regarding food (I DO NOT mean "seasoned" but "hot")?
To find islands of 1 and 0 in matrix
Why does this RX-X lock not appear in Extended Events?
Is there a more helpful way to detect lock acquire/release stats in SQL Profiler?Synchronize Queries Retrieving Sessions And Locks From DMVsHold exclusive lock on a whole DBCan I rely on reading SQL Server Identity values in order?What interval does SQL Server Profiler's “duration” refer to?Extended Events filteringExtended event for lock count does not show locksWhy adding FOREIGN KEY constraint does not lock the tableSQL Server Exclusive(X) lock not consistently blocking Shared(S) lock on a resourceWhy does an UPDATE to a full-text-indexed column lock the full text index?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}
The Problem
I have a pair of queries that, under serializable isolation, cause an RX-X lock. However, when I use Extended Events to watch lock acquisition, the RX-X lock acquisition never appears, it is only released. Where does it come from?
The Repro
Here's my table:
CREATE TABLE dbo.LockTest (
ID int identity,
Junk char(4)
)
CREATE CLUSTERED INDEX CX_LockTest --not unique!
ON dbo.LockTest(ID)
--preload some rows
INSERT dbo.LockTest
VALUES ('data'),('data'),('data')
Here's my problem batch:
SET TRANSACTION ISOLATION LEVEL SERIALIZABLE
BEGIN TRAN
INSERT dbo.LockTest
VALUES ('bleh')
SELECT *
FROM dbo.LockTest
WHERE ID = SCOPE_IDENTITY()
--ROLLBACK
I check locks held by this session, and see RX-X:
SELECT resource_type, request_mode, request_status, resource_description
FROM sys.dm_tran_locks
WHERE request_session_id = 72 --change SPID!
But I also have an Extended Event on lock_acquired
and lock_released
. I filter it on the appropriate associated_object_id...there's no RX-X.
After executing the rollback, I see RX-X (LAST_MODE) released, even though it was never acquired.
What I've Tried
I looked at all locks in Extended Events - no filtering. No RX-X locks acquired.
I also tried Profiler: same results (except of course it gets the name right...no "LAST_MODE").
I ran the XE for lock escalations - it's not there.
There's no XE specifically for conversions, but I was able to confirm that at least the U to X lock conversion is captured by
lock_acquired
Also of note is the RI-N that gets acquired but never released. My current hypothesis is that the RX-X is a conversion lock, as described here. There are overlapping key-range locks in my batch that look like they should qualify for conversion, but the RX-X lock isn't in the conversion table.
Where is this lock coming from, and why isn't it picked up by Extended Events?
sql-server locking sql-server-2017
add a comment |
The Problem
I have a pair of queries that, under serializable isolation, cause an RX-X lock. However, when I use Extended Events to watch lock acquisition, the RX-X lock acquisition never appears, it is only released. Where does it come from?
The Repro
Here's my table:
CREATE TABLE dbo.LockTest (
ID int identity,
Junk char(4)
)
CREATE CLUSTERED INDEX CX_LockTest --not unique!
ON dbo.LockTest(ID)
--preload some rows
INSERT dbo.LockTest
VALUES ('data'),('data'),('data')
Here's my problem batch:
SET TRANSACTION ISOLATION LEVEL SERIALIZABLE
BEGIN TRAN
INSERT dbo.LockTest
VALUES ('bleh')
SELECT *
FROM dbo.LockTest
WHERE ID = SCOPE_IDENTITY()
--ROLLBACK
I check locks held by this session, and see RX-X:
SELECT resource_type, request_mode, request_status, resource_description
FROM sys.dm_tran_locks
WHERE request_session_id = 72 --change SPID!
But I also have an Extended Event on lock_acquired
and lock_released
. I filter it on the appropriate associated_object_id...there's no RX-X.
After executing the rollback, I see RX-X (LAST_MODE) released, even though it was never acquired.
What I've Tried
I looked at all locks in Extended Events - no filtering. No RX-X locks acquired.
I also tried Profiler: same results (except of course it gets the name right...no "LAST_MODE").
I ran the XE for lock escalations - it's not there.
There's no XE specifically for conversions, but I was able to confirm that at least the U to X lock conversion is captured by
lock_acquired
Also of note is the RI-N that gets acquired but never released. My current hypothesis is that the RX-X is a conversion lock, as described here. There are overlapping key-range locks in my batch that look like they should qualify for conversion, but the RX-X lock isn't in the conversion table.
Where is this lock coming from, and why isn't it picked up by Extended Events?
sql-server locking sql-server-2017
add a comment |
The Problem
I have a pair of queries that, under serializable isolation, cause an RX-X lock. However, when I use Extended Events to watch lock acquisition, the RX-X lock acquisition never appears, it is only released. Where does it come from?
The Repro
Here's my table:
CREATE TABLE dbo.LockTest (
ID int identity,
Junk char(4)
)
CREATE CLUSTERED INDEX CX_LockTest --not unique!
ON dbo.LockTest(ID)
--preload some rows
INSERT dbo.LockTest
VALUES ('data'),('data'),('data')
Here's my problem batch:
SET TRANSACTION ISOLATION LEVEL SERIALIZABLE
BEGIN TRAN
INSERT dbo.LockTest
VALUES ('bleh')
SELECT *
FROM dbo.LockTest
WHERE ID = SCOPE_IDENTITY()
--ROLLBACK
I check locks held by this session, and see RX-X:
SELECT resource_type, request_mode, request_status, resource_description
FROM sys.dm_tran_locks
WHERE request_session_id = 72 --change SPID!
But I also have an Extended Event on lock_acquired
and lock_released
. I filter it on the appropriate associated_object_id...there's no RX-X.
After executing the rollback, I see RX-X (LAST_MODE) released, even though it was never acquired.
What I've Tried
I looked at all locks in Extended Events - no filtering. No RX-X locks acquired.
I also tried Profiler: same results (except of course it gets the name right...no "LAST_MODE").
I ran the XE for lock escalations - it's not there.
There's no XE specifically for conversions, but I was able to confirm that at least the U to X lock conversion is captured by
lock_acquired
Also of note is the RI-N that gets acquired but never released. My current hypothesis is that the RX-X is a conversion lock, as described here. There are overlapping key-range locks in my batch that look like they should qualify for conversion, but the RX-X lock isn't in the conversion table.
Where is this lock coming from, and why isn't it picked up by Extended Events?
sql-server locking sql-server-2017
The Problem
I have a pair of queries that, under serializable isolation, cause an RX-X lock. However, when I use Extended Events to watch lock acquisition, the RX-X lock acquisition never appears, it is only released. Where does it come from?
The Repro
Here's my table:
CREATE TABLE dbo.LockTest (
ID int identity,
Junk char(4)
)
CREATE CLUSTERED INDEX CX_LockTest --not unique!
ON dbo.LockTest(ID)
--preload some rows
INSERT dbo.LockTest
VALUES ('data'),('data'),('data')
Here's my problem batch:
SET TRANSACTION ISOLATION LEVEL SERIALIZABLE
BEGIN TRAN
INSERT dbo.LockTest
VALUES ('bleh')
SELECT *
FROM dbo.LockTest
WHERE ID = SCOPE_IDENTITY()
--ROLLBACK
I check locks held by this session, and see RX-X:
SELECT resource_type, request_mode, request_status, resource_description
FROM sys.dm_tran_locks
WHERE request_session_id = 72 --change SPID!
But I also have an Extended Event on lock_acquired
and lock_released
. I filter it on the appropriate associated_object_id...there's no RX-X.
After executing the rollback, I see RX-X (LAST_MODE) released, even though it was never acquired.
What I've Tried
I looked at all locks in Extended Events - no filtering. No RX-X locks acquired.
I also tried Profiler: same results (except of course it gets the name right...no "LAST_MODE").
I ran the XE for lock escalations - it's not there.
There's no XE specifically for conversions, but I was able to confirm that at least the U to X lock conversion is captured by
lock_acquired
Also of note is the RI-N that gets acquired but never released. My current hypothesis is that the RX-X is a conversion lock, as described here. There are overlapping key-range locks in my batch that look like they should qualify for conversion, but the RX-X lock isn't in the conversion table.
Where is this lock coming from, and why isn't it picked up by Extended Events?
sql-server locking sql-server-2017
sql-server locking sql-server-2017
asked 11 hours ago
ForrestForrest
3,2141 gold badge9 silver badges26 bronze badges
3,2141 gold badge9 silver badges26 bronze badges
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
The single row insert acquires an X
(exclusive) lock on the new row.
The SELECT
attempts to acquire a range-shared, key shared (RangeS-S
) lock.
This request is reported by the lock_acquired
Extended Event as mode = RS_S
.
It is reported by the Profiler event class Lock:Acquired
as mode 13 (LCK_M_RS_S
).
The requested mode is combined with the existing exclusive lock mode in Lock::CalculateGrantMode
in sqlmin.dll
. There is no combined mode of range-shared, key exclusive (RangeS-X
) so the outcome of the calculation is range-exclusive, key exclusive (RangeX-X
), which happens to be mode 15.
The grant mode calculation is performed just before the extended event is generated by lck_ProduceExtendedEvent<XeSqlPkg::lock_acquired>
. Nevertheless, both Profiler and Extended Events log the requested RangeS-S
mode, not the resulting lock mode RangeX-X
. This is counter to the limited documentation, which says:
Mode | int | Resulting mode after the lock was acquired.
The mode column of the extended event has no documentation at all, and the description in the meta data is blank. Perhaps Microsoft themselves weren't even sure of the behaviour.
The mysterious LAST_MODE
is something Erik Darling has remarked on before.
I have often thought it would be more useful if lock events reported both the requested and resulting modes, but that is not what we have. The current arrangement makes it pretty much impossible to track and match up lock acquisition and release.
There might be a good reason for reporting locks this way. If it doesn't meet your needs, you could open a support case with Microsoft.
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "182"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdba.stackexchange.com%2fquestions%2f244054%2fwhy-does-this-rx-x-lock-not-appear-in-extended-events%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
The single row insert acquires an X
(exclusive) lock on the new row.
The SELECT
attempts to acquire a range-shared, key shared (RangeS-S
) lock.
This request is reported by the lock_acquired
Extended Event as mode = RS_S
.
It is reported by the Profiler event class Lock:Acquired
as mode 13 (LCK_M_RS_S
).
The requested mode is combined with the existing exclusive lock mode in Lock::CalculateGrantMode
in sqlmin.dll
. There is no combined mode of range-shared, key exclusive (RangeS-X
) so the outcome of the calculation is range-exclusive, key exclusive (RangeX-X
), which happens to be mode 15.
The grant mode calculation is performed just before the extended event is generated by lck_ProduceExtendedEvent<XeSqlPkg::lock_acquired>
. Nevertheless, both Profiler and Extended Events log the requested RangeS-S
mode, not the resulting lock mode RangeX-X
. This is counter to the limited documentation, which says:
Mode | int | Resulting mode after the lock was acquired.
The mode column of the extended event has no documentation at all, and the description in the meta data is blank. Perhaps Microsoft themselves weren't even sure of the behaviour.
The mysterious LAST_MODE
is something Erik Darling has remarked on before.
I have often thought it would be more useful if lock events reported both the requested and resulting modes, but that is not what we have. The current arrangement makes it pretty much impossible to track and match up lock acquisition and release.
There might be a good reason for reporting locks this way. If it doesn't meet your needs, you could open a support case with Microsoft.
add a comment |
The single row insert acquires an X
(exclusive) lock on the new row.
The SELECT
attempts to acquire a range-shared, key shared (RangeS-S
) lock.
This request is reported by the lock_acquired
Extended Event as mode = RS_S
.
It is reported by the Profiler event class Lock:Acquired
as mode 13 (LCK_M_RS_S
).
The requested mode is combined with the existing exclusive lock mode in Lock::CalculateGrantMode
in sqlmin.dll
. There is no combined mode of range-shared, key exclusive (RangeS-X
) so the outcome of the calculation is range-exclusive, key exclusive (RangeX-X
), which happens to be mode 15.
The grant mode calculation is performed just before the extended event is generated by lck_ProduceExtendedEvent<XeSqlPkg::lock_acquired>
. Nevertheless, both Profiler and Extended Events log the requested RangeS-S
mode, not the resulting lock mode RangeX-X
. This is counter to the limited documentation, which says:
Mode | int | Resulting mode after the lock was acquired.
The mode column of the extended event has no documentation at all, and the description in the meta data is blank. Perhaps Microsoft themselves weren't even sure of the behaviour.
The mysterious LAST_MODE
is something Erik Darling has remarked on before.
I have often thought it would be more useful if lock events reported both the requested and resulting modes, but that is not what we have. The current arrangement makes it pretty much impossible to track and match up lock acquisition and release.
There might be a good reason for reporting locks this way. If it doesn't meet your needs, you could open a support case with Microsoft.
add a comment |
The single row insert acquires an X
(exclusive) lock on the new row.
The SELECT
attempts to acquire a range-shared, key shared (RangeS-S
) lock.
This request is reported by the lock_acquired
Extended Event as mode = RS_S
.
It is reported by the Profiler event class Lock:Acquired
as mode 13 (LCK_M_RS_S
).
The requested mode is combined with the existing exclusive lock mode in Lock::CalculateGrantMode
in sqlmin.dll
. There is no combined mode of range-shared, key exclusive (RangeS-X
) so the outcome of the calculation is range-exclusive, key exclusive (RangeX-X
), which happens to be mode 15.
The grant mode calculation is performed just before the extended event is generated by lck_ProduceExtendedEvent<XeSqlPkg::lock_acquired>
. Nevertheless, both Profiler and Extended Events log the requested RangeS-S
mode, not the resulting lock mode RangeX-X
. This is counter to the limited documentation, which says:
Mode | int | Resulting mode after the lock was acquired.
The mode column of the extended event has no documentation at all, and the description in the meta data is blank. Perhaps Microsoft themselves weren't even sure of the behaviour.
The mysterious LAST_MODE
is something Erik Darling has remarked on before.
I have often thought it would be more useful if lock events reported both the requested and resulting modes, but that is not what we have. The current arrangement makes it pretty much impossible to track and match up lock acquisition and release.
There might be a good reason for reporting locks this way. If it doesn't meet your needs, you could open a support case with Microsoft.
The single row insert acquires an X
(exclusive) lock on the new row.
The SELECT
attempts to acquire a range-shared, key shared (RangeS-S
) lock.
This request is reported by the lock_acquired
Extended Event as mode = RS_S
.
It is reported by the Profiler event class Lock:Acquired
as mode 13 (LCK_M_RS_S
).
The requested mode is combined with the existing exclusive lock mode in Lock::CalculateGrantMode
in sqlmin.dll
. There is no combined mode of range-shared, key exclusive (RangeS-X
) so the outcome of the calculation is range-exclusive, key exclusive (RangeX-X
), which happens to be mode 15.
The grant mode calculation is performed just before the extended event is generated by lck_ProduceExtendedEvent<XeSqlPkg::lock_acquired>
. Nevertheless, both Profiler and Extended Events log the requested RangeS-S
mode, not the resulting lock mode RangeX-X
. This is counter to the limited documentation, which says:
Mode | int | Resulting mode after the lock was acquired.
The mode column of the extended event has no documentation at all, and the description in the meta data is blank. Perhaps Microsoft themselves weren't even sure of the behaviour.
The mysterious LAST_MODE
is something Erik Darling has remarked on before.
I have often thought it would be more useful if lock events reported both the requested and resulting modes, but that is not what we have. The current arrangement makes it pretty much impossible to track and match up lock acquisition and release.
There might be a good reason for reporting locks this way. If it doesn't meet your needs, you could open a support case with Microsoft.
answered 2 hours ago
Paul White♦Paul White
57.9k15 gold badges304 silver badges477 bronze badges
57.9k15 gold badges304 silver badges477 bronze badges
add a comment |
add a comment |
Thanks for contributing an answer to Database Administrators Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdba.stackexchange.com%2fquestions%2f244054%2fwhy-does-this-rx-x-lock-not-appear-in-extended-events%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown