opserver / Opserver

Stack Exchange's Monitoring System
https://opserver.github.io/Opserver/
MIT License
4.5k stars 827 forks source link

Remove clustered indexes from the unused indexes tab #322

Open ChristopherHaws opened 6 years ago

ChristopherHaws commented 6 years ago

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! :)

NickCraver commented 5 years ago

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.