Missing Index

  • SQL语句实现查询并自动创建Missing Index

    要实现查询并自动创建缺失的索引,可以使用以下SQL语句:,,``sql,SELECT OBJECT_NAME(s.[object_id]) AS TableName,, i.name AS IndexName,, COL_NAME(ic.object_id,ic.column_id) AS ColumnName,, ic.index_id, ic.is_included_column,, USER_SEEKABLE(ic.index_id) AS IsSeekable,, ic.filter_definition,FROM sys.dm_db_missing_index_groups g,JOIN sys.dm_db_missing_index_group_stats m ON g.group_handle = m.group_handle,JOIN sys.dm_db_missing_index_details d ON m.index_handle = d.index_handle,JOIN sys.objects o ON d.object_id = o.object_id,JOIN sys.indexes i ON d.object_id = i.object_id AND d.index_id = i.index_id,JOIN sys.syscolumns c ON o.object_id = c.id AND c.colid = d.column_id,LEFT JOIN sys.partitions p ON o.object_id = p.OBJECT_ID AND i.index_id = p.index_id AND p.hobt_id = d.record_type,LEFT JOIN sys.allocation_units a ON p.partition_id = a.container_id,LEFT JOIN sys.system_internals s ON a.unit_id = s.allocunit_page_id,LEFT JOIN sys.dm_db_partition_stats ps ON p.object_id = ps.object_id AND ps.index_id = i.index_id AND ps.partition_number = p.partition_number,LEFT JOIN sys.dm_db_column_store_row_group csrg ON o.object_id = csrg.object_id AND csrg.columnstore_rowgroup_id = ps.partition_number,LEFT JOIN sys.dm_db_column_store_segments cs ON csrg.hobt_id = cs.hobt_id AND csrg.filegroup = cs.filegroup AND csrg.database_id = cs.database_id AND csrg.page_id = csrg.page_id,LEFT JOIN sys.dm_db_column_store_values ccv ON csrg.hobt_id = ccv.hobtid AND ccv.filegroup = csrg.filegroup AND ccv.database_id = csrg.database_id AND ccv.page_id = csrg.page_id AND ccvposition IS NOT NULL,LEFT JOIN sys.columns col ON o.object_id = col.object_id AND col.column_id = d.column_id,LEFT JOIN sys.computed_columns cc ON o.object_id = cc.object_id AND cc.column_id = d.column_id,WHERE i.is_primary_key = 0 AND i.is_unique = 1 AND i.is_ignored = 0 AND i.is_hypothetical = 0 AND i.has_filter = 0 AND i.allow_row_locks = 1 AND i.allow_page_locks = 1 AND i.preventive_maintenance = 0,ORDER BY gm.modification_counter DESC;,``

    2024-05-21
    099
免备案 高防CDN 无视CC/DDOS攻击 限时秒杀,10元即可体验  (专业解决各类攻击)>>点击进入