HiveBrain v1.2.0
Get Started
← Back to all entries
patternsqlMinor

Why is SQL Server 2012 Recommending This Index Be Created?

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
thiswhy2012sqlrecommendingcreatedserverindex

Problem

I have the following query:

Select SubId, Max(ReadTimeLocal)
From dbo.PanelWorkflow 
Where ProcessNumber IN (802,1190,1605,1620,1645,1660,1695,1790,1990,2690,2795,2990,3090,3290,3590,3790,4190,4390,4590,5000,5200,5400)
Group By SubId


I have the following index on the dbo.PanelWorkflow table:

CREATE NONCLUSTERED INDEX [IX_PanelWorkflow_ProcessNumber_Lineage] ON [dbo].[PanelWorkflow]
(
    [ProcessNumber] ASC,
    [Lineage] ASC
)
INCLUDE ( [SubId],[ReadTimeLocal]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)


The query plan from SSMS looks as follows:

SSMS is recommending I create the following index (with an impact of 54.3)

CREATE NONCLUSTERED INDEX []
ON [dbo].[PanelWorkflow] ([ProcessNumber])
INCLUDE ([SubId],[ReadTimeLocal])


Does anyone know why it's recommending I create an index that essentially exists already, and is not using the one that does exist?

There are 830 million rows in the table. Using SQL Server 2012.

Solution

Just to clarify, SSMS is not recommending that index, it is from the query engine/optimizer. Just to note as well a good MSDN article notes some limitations to the Missing Index Feature.

The fact that your current non-clustered index contains [ProcessNumber] and [Lineage] the query engine found simply scanning the clustered index of the table to be more optimal. It is suggesting an index strictly on ProcessNumber because the query is filtering on that column only. I believe if this is also the column that the clustered index is based on then your non-clustered indexe will be ignored by the query optimizer.

I would look into all the missing indexes the optimizer sees for this table and evaluate the current unused indexes as well.

Context

StackExchange Database Administrators Q#53068, answer score: 5

Revisions (0)

No revisions yet.