Question

I am tuning my SQL server and when I show my execution plan for one of my queries at the top it reads:

"Missing Index (Impact 99.7782): CREATE NONCLUSTERED INDEX..."

So I looked at the missing index details and it is showing this:

/*
Missing Index Details from ExecutionPlan1.sqlplan
The Query Processor estimates that implementing the following index could improve the query cost by 99.7782%.
*/

/*
USE [phsprod]
GO
CREATE NONCLUSTERED INDEX [<Name of Missing Index, sysname,>]
ON [dbo].[address] ([userid])

GO
*/

I have only been working with SQL for about a month now and I have never done anything with this as all my tables have been built for me already. Can anyone help explain/give me any ideas on what to do with this? Thanks.

Was it helpful?

Solution

That means SQL Server is suggesting that your query could run faster with an index. Indexes add overhead and disk storage, so you should ignore this hint unless the query is giving performance problems in production.

To create the index, uncomment the statement after use, replace [<Name of Missing Index, sysname,>] with a real name, and run it:

USE [phsprod]
GO
CREATE NONCLUSTERED INDEX IX_Address_UserId
ON [dbo].[address] ([userid])

OTHER TIPS

That means SQL Server is suggesting that your query could run faster with this index.

It can mean that your current indexes are not the greatest for the query you are running. Maybe your query could be optimised. Or maybe you COULD add the index. But if you decide to do this, you have to analyse carefully.

Indeed, indexes add overhead and disk storage. But, it can also improve performance. For instance, if you always search in your table based on a "userid", then maybe it can payoff to add an index on that column, since SQL will be able to search usign this index.

Think a little bit of this like if you search for a word in a dictionnary. If your looking for the word "dog", your going to search for "d" and then words that begin with "do" to finally find the word "dog".

If the words were not in alphabetical order in the dictionnary, you would have to search the whole dictionnary to find the word "dog"!

A clustered index (or a primary key) is the order of your columns. Right now, it seems that you don't have an index on the column "userid". So SQL Server has (probably) to scan the entire table until he finds the userid.

If you add a nonclustered index, it will not re-order your table, but it will tell SQL Server between what range he should search to find the userid you want to. (Like "in the dictionnary, between page 20 and 30") So it will not have to search the whole table to find it.

But it also means that when you add new data to the table, or remove, or modify, he needs to keep his index up-to-date. Generally, a few indexes don't hurt, but you need to be sure they are needed. You don't want to add too much indexes as they can hurt performances if you add too much.

And if your table contains only a few hundreds of rows, maybe it won't show you a big improvement of performances. But over time, when your table grows, it may make a difference.

Hope that helps!

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