/SQL-Server-Indexes-With-Unused-INCLUDE-Columns

Scripts that scan for INCLUDE columns that are never referenced in query execution plans

Primary LanguageTSQLMIT LicenseMIT

SQL Server Indexes With Unused INCLUDE Columns

This repository of T-SQL scripts attempts to identify INCLUDE columns in non-clustered indexes that are not being referenced, and could presumably be removed from the index definition. (There's a short article about this repo on my blog/site.) The scripts are as follows:

01 Create, Populate Table.sql

Creates a "permanent" table within [tempdb] and populates it with meta data for all nonclustered index INCLUDE columns.

02 Create Table.sql

Creates a "permanent" table to hold all query plans.

03 Load Query Plans from Plan Cache.sql

Loads query plans from plan cache into a table.

04 Load Query Plans from Query Store.sql

Loads query plans from Query Store in every database (if enabled/on) into a table.

05 Parse Query Plans.sql

Parses the table of query plans, and updates a table when INCLUDE columns are found.

06 Results.sql

Queries that help analyze the results.

Credits

Many thanks to Jonathan Kehayias (Twitter | Blog) for his guidance with the scripts. He helped me with the XML parsing/syntax that identified index scans and their column references.