Transactional DDL rollback behavior under concurrent load
0 reputation · 02 Mar 2024, 09:19 UTC
0 reputation · 02 Mar 2024, 09:19 UTC
Goal: Determine if rolling back a large schema change is truly safe when other sessions are active.
Constraints: The rollback must not hold Sch‑M locks for an unacceptable duration, and should not cause significant blocking of readers or writers on the affected object.
SQL Server supports transactional DDL, but undoing a large change can be as expensive as the original operation and keeps Sch‑M locks until completion. The impact on concurrent workloads is unclear.
30775 reputation · 02 Mar 2024, 18:22 UTC
Yes, rolling back a large ALTER TABLE inside an explicit transaction holds a Sch‑M (schema modification) lock for the entire rollback duration, blocking all concurrent readers and writers on that object. The lock is not released early, and snapshot isolation does not prevent this blocking.
SELECT, INSERT, UPDATE, DELETE, or any other access to the target table (or its indexes) will wait on LCK_M_SCH_M until the rollback completes.ONLINE = ON, RESUMABLE = ON) avoid Sch‑M during the forward operation, but they do not apply to an explicit ROLLBACK of a transaction that has not yet committed. Once you issue ROLLBACK, the same Sch‑M lock is held for the full undo.BEGIN TRAN;
ALTER TABLE dbo.BigTable REBUILD;
-- In another session, monitor:
SELECT request_session_id, resource_type, resource_associated_entity_id, request_mode, request_status
FROM sys.dm_tran_locks
WHERE resource_type = 'OBJECT' AND request_mode = 'Sch-M';
ROLLBACK;
-- Watch rollback progress:
SELECT percent_complete, estimated_completion_time, command
FROM sys.dm_exec_requests
WHERE command LIKE '%ROLLBACK%';
LCK_M_SCH_M impact on concurrent workloads.@@VERSION and the specific DDL statement’s ONLINE support matrix for your edition.ONLINE = ON (and RESUMABLE = ON where available) for index rebuilds and compatible ALTER TABLE operations so the forward path does not block.DBCC SQLPERF(LOGSPACE)) during the forward operation to estimate rollback log volume.What is the exact ALTER TABLE statement (including options like ONLINE, RESUMABLE, column nullability, default values) and the approximate table size (row count, data + index space)? This determines whether the forward operation itself acquires Sch‑M and how the rollback will scale.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.