Skip to content

Commit 23a3dcc

Browse files
Merge pull request #544 from erikdarlingdata/dev
Dev
2 parents acf7dd7 + b1366da commit 23a3dcc

2 files changed

Lines changed: 159 additions & 92 deletions

File tree

sp_IndexCleanup/README.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,13 @@ The procedure requires SQL Server 2012 (11.0) or later due to the use of FORMAT
2323
| Parameter Name | Data Type | Default Value | Description |
2424
|----------------|-----------|---------------|-------------|
2525
| @database_name | sysname | NULL | The name of the database you wish to analyze |
26-
| @schema_name | sysname | NULL | The schema name to filter indexes by |
26+
| @schema_name | sysname | NULL | The schema name to filter indexes by - limits analysis to tables in the specified schema |
2727
| @table_name | sysname | NULL | The table name to filter indexes by |
2828
| @min_reads | bigint | 0 | Minimum number of reads for an index to be considered used |
2929
| @min_writes | bigint | 0 | Minimum number of writes for an index to be considered used |
3030
| @min_size_gb | decimal(10,2) | 0 | Minimum size in GB for an index to be analyzed |
3131
| @min_rows | bigint | 0 | Minimum number of rows for a table to be analyzed |
32+
| @dedupe_only | bit | 0 | When set to 1, only performs index deduplication but does not mark unused indexes for removal |
3233
| @get_all_databases | bit | 0 | When set to 1, analyzes all eligible databases on the server |
3334
| @include_databases | nvarchar(max) | NULL | Comma-separated list of databases to include (used with @get_all_databases = 1) |
3435
| @exclude_databases | nvarchar(max) | NULL | Comma-separated list of databases to exclude (used with @get_all_databases = 1) |
@@ -50,6 +51,16 @@ EXECUTE dbo.sp_IndexCleanup
5051
@table_name = 'YourTable',
5152
@debug = 1;
5253

54+
-- Only perform deduplication without marking unused indexes for removal
55+
EXECUTE dbo.sp_IndexCleanup
56+
@database_name = 'YourDatabase',
57+
@dedupe_only = 1;
58+
59+
-- Analyze tables in a specific schema only
60+
EXECUTE dbo.sp_IndexCleanup
61+
@database_name = 'YourDatabase',
62+
@schema_name = 'YourSchema';
63+
5364
-- Filter indexes by minimum usage thresholds
5465
EXECUTE dbo.sp_IndexCleanup
5566
@database_name = 'YourDatabase',
@@ -79,6 +90,7 @@ EXECUTE dbo.sp_IndexCleanup
7990
## Notes
8091

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

0 commit comments

Comments
 (0)