Skip to content
Permalink
Browse files

Integrate missing index query in the new Datagrid + filter on the dat…

…abase
  • Loading branch information...
gboge committed Mar 12, 2018
1 parent 8823639 commit c15a0dc0278d509b2e661aee7d663ebf947f3745
Showing with 12 additions and 11 deletions.
  1. +12 −11 KDatabase.cs
@@ -705,15 +705,15 @@ public static DataTable GetExpensiveIndexes(this smo.Database d)
public static DataTable GetMissingIndexes(this smo.Database d)
{
string sql = @"SELECT mid.[statement] AS [Table]
, mid.equality_columns AS [Equality_Columns]
, mid.inequality_columns AS [Inequality_Columns]
, mid.included_columns AS [Included_Columns]
, migs.unique_compiles AS [Unique_Compiles]
, migs.last_user_seek AS [Last_User_Seek]
, migs.user_seeks AS [User_Seeks]
, ROUND(migs.avg_total_user_cost, 2) AS [Average_Total_User_Cost]
, migs.avg_user_impact AS [Average_User_Impact]
, ROUND(user_seeks * avg_total_user_cost * (avg_user_impact * 0.01), 2) AS [Index_Advantage]
, mid.equality_columns AS [Equality Columns]
, mid.inequality_columns AS [Inequality Columns]
, mid.included_columns AS [Included Columns]
, migs.unique_compiles AS [Unique Compiles]
, migs.last_user_seek AS [Last User Seek]
, migs.user_seeks AS [User Seeks]
, ROUND(migs.avg_total_user_cost, 2) AS [Avg Total User Cost]
, migs.avg_user_impact AS [Avg User Impact]
, ROUND(user_seeks * avg_total_user_cost * (avg_user_impact * 0.01), 2) AS [Index Advantage]
, 'CREATE NONCLUSTERED INDEX [IX_' + OBJECT_NAME(mid.OBJECT_ID,mid.database_id) + '_'
+ REPLACE(REPLACE(REPLACE(ISNULL(mid.equality_columns,''),', ','_'),'[',''),']','') +
CASE
@@ -728,11 +728,12 @@ public static DataTable GetMissingIndexes(this smo.Database d)
'' END
+ ISNULL (mid.inequality_columns, '')
+ ')'
+ ISNULL (' INCLUDE (' + mid.included_columns + ')', '') AS [Creation_Script]
+ ISNULL (' INCLUDE (' + mid.included_columns + ')', '') AS [__script]
FROM sys.dm_db_missing_index_group_stats AS migs WITH (NOLOCK)
INNER JOIN sys.dm_db_missing_index_groups AS mig WITH (NOLOCK) ON migs.group_handle = mig.index_group_handle
INNER JOIN sys.dm_db_missing_index_details AS mid WITH (NOLOCK) ON mig.index_handle = mid.index_handle
ORDER BY [Index_Advantage] DESC";
WHERE mid.database_id = DB_ID()
ORDER BY [Index Advantage] DESC";
return d.ExecuteWithResults(sql).Tables[0];
}
#endregion

0 comments on commit c15a0dc

Please sign in to comment.
You can’t perform that action at this time.