Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

which is worse - missing index or unused indexes

Posted on 2010-01-12
3
Medium Priority
?
347 Views
Last Modified: 2012-05-08
If there 90% of the indexes are not used or there are lot of indexes that could be there- what factors determine which is worse or better than the other option.

thanks
0
Comment
Question by:anushahanna
3 Comments
 
LVL 75

Accepted Solution

by:
Aneesh Retnakaran earned 668 total points
ID: 26294289
unused will be worse ,as it consumes some cpu and space
0
 
LVL 60

Assisted Solution

by:chapmandew
chapmandew earned 668 total points
ID: 26294325
unused consumes space, but I do not think it is worse.  Missing indexes are worse as they can affect queries hitting the tables, which can in turn slow down everything hitting the system.  Unused indexes just won't be used.  
0
 
LVL 4

Assisted Solution

by:Ram4020
Ram4020 earned 664 total points
ID: 26294733
Both has its own disadvantages.

Ideally there should not be any unused and mising indexes. It depends on the statistics. Run the below query and you will know which is very bad in your system.

-- Missing indexes
/***********************************************************************************************************/
SELECT
  migs.avg_total_user_cost * (migs.avg_user_impact / 100.0) * (migs.user_seeks + migs.user_scans) AS improvement_measure,
  'CREATE INDEX [missing_index_' + CONVERT (varchar, mig.index_group_handle) + '_' + CONVERT (varchar, mid.index_handle)
  + '_' + LEFT (PARSENAME(mid.statement, 1), 32) + ']'
  + ' ON ' + mid.statement
  + ' (' + ISNULL (mid.equality_columns,'')
    + CASE WHEN mid.equality_columns IS NOT NULL AND mid.inequality_columns IS NOT NULL THEN ',' ELSE '' END
    + ISNULL (mid.inequality_columns, '')
  + ')'
  + ISNULL (' INCLUDE (' + mid.included_columns + ')', '') AS create_index_statement,
  migs.*, mid.database_id, mid.[object_id]
FROM sys.dm_db_missing_index_groups mig
INNER JOIN sys.dm_db_missing_index_group_stats migs ON migs.group_handle = mig.index_group_handle
INNER JOIN sys.dm_db_missing_index_details mid ON mig.index_handle = mid.index_handle
WHERE migs.avg_total_user_cost * (migs.avg_user_impact / 100.0) * (migs.user_seeks + migs.user_scans) > 10
ORDER BY migs.avg_total_user_cost * migs.avg_user_impact * (migs.user_seeks + migs.user_scans) DESC

-- Rarely used or Unused indexes
declare @dbid int

select @dbid = db_id()
select objectname=object_name(s.object_id), s.object_id, indexname=i.name, i.index_id
            , user_seeks, user_scans, user_lookups, user_updates
from sys.dm_db_index_usage_stats s,
            sys.indexes i
where database_id = @dbid and objectproperty(s.object_id,'IsUserTable') = 1
and i.object_id = s.object_id
and i.index_id = s.index_id
order by (user_seeks + user_scans + user_lookups + user_updates) asc
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When writing XML code a very difficult part is when we like to remove all the elements or attributes from the XML that have no data. I would like to share a set of recursive MSSQL stored procedures that I have made to remove those elements from …
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Screencast - Getting to Know the Pipeline

564 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question