Question

I have a large table with at the moment 2500000 rows in sql server 2012. The primary key is listed as Create as clustered: Yes and since the primary key is a uniqueidentifier I would like to change it to be non-clustered for starters (and then at some time in the future, cluster on the date column instead).

The problem is that this times out. How can it be slow to disable clustering of an index? And what can I do to speed this up and finish before the timeout, except increasing the timeout to 24 hours for this operation?

Was it helpful?

Solution

It will take a long time because as it is a clustered index, removing it will cause the entire table to be rebuilt as a heap, and as you have a lot of rows (and if your table is particularly wide) this can take a long time depending on your IO performance.

Also, you would probably want to carefully consider adding a clustered index on the date column as this is not guaranteed to be unique (therefore SQL server will add a uniquifier to the clustering key, reducing it's efficiency and that of all other non-clustered indexes on the table) also, if your dates are not always added in ascending or descending order, you will fragment the table, forcing SQL server to perform page splits to fit values into the middle of the table rather than the end.

The best columns for clustering are narrow, unique and always increasing/decreasing in value. Identity columns are a perfect candidate.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top