Skip to content

Find dbadbmissingindexAdd Find-DbaDbMissingIndex - #10779

Open
deepeshd87 wants to merge 2 commits into
dataplat:developmentfrom
deepeshd87:find-dbadbmissingindex
Open

deepeshd87 wants to merge 2 commits into
dataplat:developmentfrom
deepeshd87:find-dbadbmissingindex

Conversation

@deepeshd87

Copy link
Copy Markdown
Contributor

Type of Change

  • New feature (non-breaking change, adds functionality)
  • Unit test is included

Implements #10770.

Purpose

dbatools has Find-DbaDbDuplicateIndex, Find-DbaDbUnusedIndex, and
Find-DbaDbDisabledIndex, but no missing-index counterpart. This adds a read-only
Find-DbaDbMissingIndex that surfaces suggestions from the sys.dm_db_missing_index_*
DMVs, ranked by impact, with a generated CREATE INDEX statement for review.

Approach (per the design discussed in #10770)

  • Score uses avg_total_user_cost * avg_user_impact * (user_seeks + user_scans); the
    three inputs are returned as their own properties so results can be re-ranked.
  • Per-database with WHERE mid.database_id = DB_ID(), correct on Azure SQL Database.
  • On SQL 2019+, joins sys.dm_db_missing_index_group_stats_query alongside group_stats
    (not replacing it) for QueryHash / LastSqlHandle.
  • Overlapping existing indexes are named in OverlappingIndex rather than filtered out.
  • Returns instance StartTime and LastUserSeek/LastUserScan; warns at the 600-group
    collection limit; help notes the counter reset conditions.
  • CREATE statement orders equality -> inequality -> INCLUDE, no edition-specific options.
  • SQL 2005+ floor. Help notes VIEW SERVER STATE / VIEW SERVER PERFORMANCE STATE (2022+)
    requirement, that suggestions are candidates for human review, and links
    Invoke-DbaDiagnosticQuery.

Testing

Verified against a seeded fixture on SQL Server 2022: the DMV query, per-database
scoping, the ImpactScore and its inputs, the generated CREATE statement, the SMO
overlap detection, and the 2019+ query-text join (QueryHash/LastSqlHandle, no
double-counting) all return correctly. I wasn't able to run the full in-module Pester
suite locally, so I'm relying on CI for the end-to-end run.

(Second contribution — previously added Find-DbaDbQueryStoreRegression in 2.9.0.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant