Opserver icon indicating copy to clipboard operation
Opserver copied to clipboard

Remove clustered indexes from the unused indexes tab

Open ChristopherHaws opened this issue 7 years ago • 1 comments

We have several transactional tables where our primary key is a guid and our unique cluster key is an auto incrementing int. Since SQL Server stores rows on disk based on the cluster key, we chose to have the cluster key be an auto incrementing int instead of a random guid to prevent fragmentation and page splits. For these cases, we never query on the cluster key, but the clustered index is used to prevent the table from being a heap. The Unused Indexes tab shows these clustered indexes when I believe it shouldn't (especially since clustered indexes tell SQL Server the order to store the data on disk meaning they are always used).

For example, for the following table, the CK_LineItem index is showing up in the Unused Indexes tab but shouldn't:

CREATE TABLE [dbo].[LineItem] (
    [Id] UNIQUEIDENTIFIER NOT NULL,
    [ClusterKey] BIGINT NOT NULL IDENTITY(1,1),
    CONSTRAINT [PK_LineItem] PRIMARY KEY NONCLUSTERED ([ID] ASC) WITH (FILLFACTOR = 80),
    CONSTRAINT [CK_LineItem] UNIQUE CLUSTERED ([ClusterKey] ASC)
)

Thanks! :)

ChristopherHaws avatar Jul 05 '18 23:07 ChristopherHaws

I'm trying to get through the backlog here. Strictly speaking, it is an unused index, so the view isn't wrong. Perhaps we can make this an option though - will flag it as an enhancement to look at after the ASP.NET Core 3 move which is underway now.

NickCraver avatar Jul 09 '19 01:07 NickCraver