There are many possible explanations for this. It may be that you have to accept it as the cost of making an improvement but it may be highlighting issues elsewhere in the system. Possible causes:
- Fragmentation of the table.
- Fragmentation of the physical database files.
- Poor choice of clustered index key.
- Large table with low percentage of its data in the buffer pool, requiring lots of physical IO to read.
- Lack of spare memory/io/cpu capacity to deal with this one off task on top of the normal workload.
- Index creation requiring tempdb for sorting but tempdb on same drive as data and or log files.
Your question is a little sparse on the details necessary to provide a conclusive answer. To start with, can you add the table DDL (including clustered index definition) to your question along with row counts and database size. Also, a description of the server spec (memory, cpu, drive configuration) and whether or not tempdb is on a separate array.
Next, the following will give us an indication of how your IO subsystem is performing.
SELECT
DB_NAME(fs.database_id) AS [Database Name]
, mf.physical_name
, io_stall_read_ms
, num_of_reads
, CAST(io_stall_read_ms / (1.0 + num_of_reads) AS NUMERIC(10, 1)) AS [avg_read_stall_ms]
, io_stall_write_ms
, num_of_writes
, CAST(io_stall_write_ms / (1.0 + num_of_writes) AS NUMERIC(10, 1)) AS [avg_write_stall_ms]
, io_stall_read_ms + io_stall_write_ms AS [io_stalls]
, num_of_reads + num_of_writes AS [total_io]
, CAST((io_stall_read_ms + io_stall_write_ms) / (1.0 + num_of_reads
+ num_of_writes) AS NUMERIC(10, 1)) AS [avg_io_stall_ms]
FROM
sys.dm_io_virtual_file_stats(NULL, NULL) AS fs
INNER JOIN
sys.master_files AS mf
ON fs.database_id = mf.database_id
AND fs.[file_id] = mf.[file_id]
ORDER BY
avg_io_stall_ms DESC
OPTION
(RECOMPILE) ;
The following will tell us how badly fragmented your existing indexes are. You may want to run this at a quiet time as it can impact on performance.
SELECT
DB_NAME(database_id) AS [Database Name]
, OBJECT_NAME(ps.OBJECT_ID) AS [Object Name]
, i.name AS [Index Name]
, ps.index_id
, index_type_desc
, avg_fragmentation_in_percent
, fragment_count
, page_count
FROM
sys.dm_db_index_physical_stats(DB_ID(), NULL, NULL, NULL, 'LIMITED') AS ps
INNER JOIN
sys.indexes AS i
ON ps.[object_id] = i.[object_id]
AND ps.index_id = i.index_id
WHERE
database_id = DB_ID()
AND page_count > 500
ORDER BY
avg_fragmentation_in_percent DESC ;
OK, enough brain cells are dead.
SQL Fiddle
WITH cte AS
(
SELECT
[ICFilterID],
[ParentID],
[FilterDesc],
[Active],
CAST(0 AS varbinary(max)) AS Level
FROM [dbo].[ICFilters]
WHERE [ParentID] = 0
UNION ALL
SELECT
i.[ICFilterID],
i.[ParentID],
i.[FilterDesc],
i.[Active],
Level + CAST(i.[ICFilterID] AS varbinary(max)) AS Level
FROM [dbo].[ICFilters] i
INNER JOIN cte c
ON c.[ICFilterID] = i.[ParentID]
)
SELECT
[ICFilterID],
[ParentID],
[FilterDesc],
[Active]
FROM cte
ORDER BY [Level];
Best Answer
Your problem is not the primary key. It is a misunderstanding of what a clustered index is. If you look at your structure you will see that the primary key is clustered. This is the default and fairly normal but is not always the case so it pays to check.
The clustered index is basically the table itself. The data pages of the clustered index are the data pages of the table. So your 450mb for the primary key is mostly the data of the table itself. At 446264K that makes it about 1k per row which is not unreasonable depending on the amount of data in the AuthorURL and Comment columns.