Skip to content
Merged

Dev #544

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion sp_IndexCleanup/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@ The procedure requires SQL Server 2012 (11.0) or later due to the use of FORMAT
| Parameter Name | Data Type | Default Value | Description |
|----------------|-----------|---------------|-------------|
| @database_name | sysname | NULL | The name of the database you wish to analyze |
| @schema_name | sysname | NULL | The schema name to filter indexes by |
| @schema_name | sysname | NULL | The schema name to filter indexes by - limits analysis to tables in the specified schema |
| @table_name | sysname | NULL | The table name to filter indexes by |
| @min_reads | bigint | 0 | Minimum number of reads for an index to be considered used |
| @min_writes | bigint | 0 | Minimum number of writes for an index to be considered used |
| @min_size_gb | decimal(10,2) | 0 | Minimum size in GB for an index to be analyzed |
| @min_rows | bigint | 0 | Minimum number of rows for a table to be analyzed |
| @dedupe_only | bit | 0 | When set to 1, only performs index deduplication but does not mark unused indexes for removal |
| @get_all_databases | bit | 0 | When set to 1, analyzes all eligible databases on the server |
| @include_databases | nvarchar(max) | NULL | Comma-separated list of databases to include (used with @get_all_databases = 1) |
| @exclude_databases | nvarchar(max) | NULL | Comma-separated list of databases to exclude (used with @get_all_databases = 1) |
Expand All @@ -50,6 +51,16 @@ EXECUTE dbo.sp_IndexCleanup
@table_name = 'YourTable',
@debug = 1;

-- Only perform deduplication without marking unused indexes for removal
EXECUTE dbo.sp_IndexCleanup
@database_name = 'YourDatabase',
@dedupe_only = 1;

-- Analyze tables in a specific schema only
EXECUTE dbo.sp_IndexCleanup
@database_name = 'YourDatabase',
@schema_name = 'YourSchema';

-- Filter indexes by minimum usage thresholds
EXECUTE dbo.sp_IndexCleanup
@database_name = 'YourDatabase',
Expand Down Expand Up @@ -79,6 +90,7 @@ EXECUTE dbo.sp_IndexCleanup
## Notes

- The procedure issues a warning when server uptime is less than 14 days, as index usage stats may not be representative
- When server uptime is less than 7 days, @dedupe_only mode is automatically enabled to prevent removing unused indexes with insufficient usage data
- Certain features like online index operations and compression are only available in specific SQL Server editions (Enterprise, Azure SQL DB, Managed Instance)
- It is recommended to have a recent backup before making any index changes
- The multi-database processing feature (@get_all_databases) analyzes each database sequentially for better performance and resource management
Expand Down
Loading