From 4bdebe4deb34bf63b238799ce5d15a39321847d1 Mon Sep 17 00:00:00 2001 From: Erik Darling <2136037+erikdarlingdata@users.noreply.github.com> Date: Thu, 26 Mar 2026 06:44:16 -0400 Subject: [PATCH] sp_IndexCleanup: fix heap table index detection (#727) The partition stats row count filter used ps.index_id = 1 which only matches clustered indexes. Heaps use index_id = 0, so heap tables were excluded entirely from deduplication analysis. Changed to ps.index_id IN (0, 1) to include both heaps and clustered. Closes #727 Co-Authored-By: Claude Opus 4.6 (1M context) --- sp_IndexCleanup/sp_IndexCleanup.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sp_IndexCleanup/sp_IndexCleanup.sql b/sp_IndexCleanup/sp_IndexCleanup.sql index 5d0da580..a361cad7 100644 --- a/sp_IndexCleanup/sp_IndexCleanup.sql +++ b/sp_IndexCleanup/sp_IndexCleanup.sql @@ -2311,7 +2311,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. nvarchar(MAX), N'.sys.dm_db_partition_stats ps WHERE ps.object_id = i.object_id - AND ps.index_id = 1 + AND ps.index_id IN (0, 1) AND ps.row_count >= @min_rows )' );