Troubleshooting Guide: Error 10660 — Online Index Build Chosen as Deadlock Victim
Why This Error Happens
This error occurs when an online index rebuild operation repeatedly conflicts with concurrent transactions attempting to modify the same row(s), causing SQL Server’s lock manager to resolve the deadlock by killing the index build process. It typically happens when long-running or frequent DML operations (INSERT/UPDATE/DELETE) hold row-level or page-level locks on the underlying table while the online index operation attempts to acquire a schema modification (Sch-M) or update lock during its final phase. High-concurrency OLTP workloads with poor transaction isolation settings or excessively long-running transactions are the most common triggers.
Step-by-Step Resolution Guide
Step 1: Identify the Blocking Session
- Open SQL Server Management Studio (SSMS) and run
sp_whoisactiveor querysys.dm_exec_requestsjoined withsys.dm_os_waiting_tasksto find sessions blocking the index operation. - Look specifically for sessions with
wait_typevalues likeLCK_M_SCH_MorLCK_M_Utied to the table being indexed. - Note the
blocking_session_idand the SPID of the online index build.
Step 2: Reduce Lock Contention During the Build
- Re-run the index operation with a lower concurrency footprint using the
MAX_DURATIONandWAIT_AT_LOW_PRIORITYoptions (available in SQL Server 2025):
ALTER INDEX IX_YourIndex ON dbo.YourTable
REBUILD WITH (ONLINE = ON (WAIT_AT_LOW_PRIORITY (MAX_DURATION = 5 MINUTES, ABORT_AFTER_WAIT = SELF)));
- This forces the operation to wait briefly for a low-priority lock slot instead of forcibly deadlocking out other transactions.
Step 3: Schedule the Rebuild During Low-Traffic Windows
- Use SQL Server Agent (via SSMS or
sqlcmd) to schedule the index rebuild job during off-peak hours when transaction volume is lower. - Navigate to SQL Server Agent > Jobs > New Job in SSMS and set the schedule under the Schedules tab.
- Confirm the Windows Server 2025 task scheduler isn’t running conflicting maintenance plans at the same time via
Task Scheduler > Task Scheduler Library.
Step 4: Adjust Transaction Isolation Level on Competing Queries
- Check the application code or stored procedures running concurrently and consider setting
READ_COMMITTED_SNAPSHOT ONat the database level to reduce blocking:
ALTER DATABASE YourDatabase SET READ_COMMITTED_SNAPSHOT ON;
- This shifts read operations to use row versioning instead of shared locks, reducing contention with the online index build.
Step 5: Shorten Long-Running Transactions
- Audit application logic for transactions that remain open longer than necessary (e.g., missing
COMMITstatements or long-held explicit transactions). - Use
DBCC OPENTRANto check for any old open transactions holding locks on the target table before retrying the index operation.
Alternative or Verification Steps
- Re-run the
ALTER INDEX ... REBUILDcommand and monitorsys.dm_exec_requestsfor the operation completing without hitting Error 10660 again. - If the issue persists, consider rebuilding the index offline during a maintenance window (
ONLINE = OFF) as a fallback, since offline rebuilds are not subject to the same row-level deadlock victim selection.