SQL Server Non Clustered Index CREATE taking forever to cancel

Nick Ryan 221 Reputation points
2024-05-23T00:03:03.8166667+00:00

I ran a CREATE NON CLUSTERED INDEX command for 1.5 hours. Decided to cancel it because it was stopping other things running. The command has now been running for 22 hours. What is it doing that takes so long to roll back?

The table is 2 billion rows and the clustered index is a columnstore.

The version of SQL Server is 2022.

There are no other jobs running on it (although that is only a recent development).

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
14,011 questions
SQL Server Transact-SQL
SQL Server Transact-SQL
SQL Server: A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.Transact-SQL: A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
102 questions
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. LiHongMSFT-4306 28,041 Reputation points
    2024-05-23T06:39:41.9066667+00:00

    Hi @Nick Ryan

    It will take a while if you have 2 billion rows, the time required to create an index is proportional to the number of rows you have.

    What is it doing that takes so long to roll back?

    Have you check whether SQL Server has an I/O problem?

    Best regards,

    Cosmog Hong


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".


  2. Ben Miller-(DBADuck) 190 Reputation points MVP
    2024-05-28T23:25:31.34+00:00

    It will definitely take a while. The amount of time it runs is not directly related to how long it will take to roll it back if you kill it. But you can use this query during those times to see how it is doing.

    If you are on SQL 2017 and above consider using RESUMABLE indexing, if your edition supports it. Then you can just suspend it and resume it later on.

    select 
    	dt.transaction_id,
    	DB_NAME(dt.database_id) as dbname,
    	dt.database_transaction_log_bytes_used,
    	dt.database_transaction_log_bytes_reserved
    from sys.dm_tran_database_transactions AS dt
    INNER JOIN sys.dm_tran_session_transactions st on dt.transaction_id = st.transaction_id
    WHERE st.session_id = <replace with spid>
    
    
    0 comments No comments

  3. Bruce (SqlWork.com) 66,706 Reputation points
    2024-05-29T00:35:29.69+00:00

    Rollback is a lot slower than commit. So if you cancel 1 1/2 hours in, it will take several hours to rollback. Don’t restart the sql as this cause the rollback to start over on restart, losing all time you have waited.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.