*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=
Util_MissingIndexes
By Jesse Roberge - YeshuaAgapao@Yahoo.com
Update 1:
Fixed broken order by (data tyep conversion error) for @Sort=3, 4, and 5
Update 2:
Added a missing 'sys.' name-part in the join to sys.dm_db_missing_index_details. Was causing the proc to return no results on some peoples' systems.
Also updated the description with the permission requirements and the effect of running without sufficient permissions.
Update 3 2009-01-14:
Fixed Rows Output - Was being erroneously multiplied by (1+#NonClusteredIndexes)
SUM(Rows) Should be SUM(CASE WHEN index_id BETWEEN 0 AND 1 THEN row_count ELSE 0 END)
Added 'Last xxx' datetime columns to the result set
Added @Delimiter parameter for the column listing output (Defaults to ,) for accomodating export to csv files.
Reports stats on what the query optimizer records in the DMVs as missing indexes and what it says the cost savings will be if they were present. Can limit by table / schema name patterns.
Requires the 'VIEW SERVER STATE' permission. The sysadmin fixed server role has this permission. dbo (datase owner) gives 'VIEW DATABASE STATE', which is not sufficient. If you run this without sufficent permissions, you will get a empty result set.
Required Input Parameters
none
Optional Input Parameters
@SchemaName sysname='' Filters schemas. All schemas if blank. Accepts LIKE Wildcards.
@TableName sysname='' Filters tables. All tables if blank. Accepts LIKE Wildcards.
@Sort Tinyint=1 Determines what to sort the results by:
Value Sort Columns
1 Score DESC, user_seeks DESC, avg_total_user_cost DESC
2 Score ASC, user_seeks ASC, equality_columns ASC
3 SchemaName ASC, TableName ASC, SeekColumns ASC
4 SchemaName ASC, TableName ASC, Score DESC
5 SchemaName ASC, TableName ASC, Score ASC
Usage:
EXECUTE Util_MissingIndexes 'dbo', 'visit%', 1
Copyright:
Licensed under the L-GPL - a weak copyleft license - you are permitted to use this as a component of a proprietary database and call this from proprietary software.
Copyleft lets you do anything you want except plagarize, conceal the source, proprietarize modifications, or prohibit copying & re-distribution of this script/proc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
see <http://www.fsf.org/licensing/licenses/lgpl.html> for the license text.
*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=