@@ -149,6 +149,8 @@ IF OBJECT_ID('tempdb..#DatabaseList') IS NOT NULL
149149IF OBJECT_ID (' tempdb..#Statistics' ) IS NOT NULL
150150 DROP TABLE #Statistics ;
151151
152+ IF OBJECT_ID (' tempdb..#PartitionCompressionInfo' ) IS NOT NULL
153+ DROP TABLE #PartitionCompressionInfo;
152154
153155 RAISERROR (N ' Create temp tables.' ,0 ,1 ) WITH NOWAIT ;
154156 CREATE TABLE #BlitzIndexResults
@@ -513,6 +515,11 @@ IF OBJECT_ID('tempdb..#Statistics') IS NOT NULL
513515 DatabaseName NVARCHAR (256 )
514516 )
515517
518+ CREATE TABLE #PartitionCompressionInfo (
519+ [index_sanity_id] INT NULL ,
520+ [partition_compression_detail] VARCHAR (8000 ) NULL
521+ )
522+
516523 CREATE TABLE #Statistics (
517524 database_name NVARCHAR (256 ) NOT NULL ,
518525 table_name NVARCHAR (128 ) NULL ,
@@ -1379,6 +1386,51 @@ BEGIN TRY
13791386 FROM #IndexSanity
13801387 WHERE database_id = @DatabaseID;
13811388
1389+ ;WITH [maps]
1390+ AS ( SELECT
1391+ index_sanity_id,
1392+ partition_number,
1393+ data_compression_desc,
1394+ partition_number - ROW_NUMBER () OVER (PARTITION BY ips .index_sanity_id , data_compression_desc ORDER BY partition_number ) AS [rN]
1395+ FROM #IndexPartitionSanity ips
1396+ ),
1397+ [grps]
1398+ AS ( SELECT MIN ([maps].[partition_number]) AS [MinKey] ,
1399+ MAX ([maps].[partition_number]) AS [MaxKey] ,
1400+ index_sanity_id,
1401+ maps .data_compression_desc
1402+ FROM [maps]
1403+ GROUP BY [maps].[rN], index_sanity_id, maps .data_compression_desc )
1404+ INSERT #PartitionCompressionInfo
1405+ (index_sanity_id, partition_compression_detail)
1406+ SELECT DISTINCT grps .index_sanity_id , SUBSTRING (( STUFF ((SELECT ' , ' + ' Partition'
1407+ + CASE WHEN [grps2].[MinKey] < [grps2].[MaxKey]
1408+ THEN + ' s '
1409+ + CAST ([grps2].[MinKey] AS VARCHAR )
1410+ + ' - '
1411+ + CAST ([grps2].[MaxKey] AS VARCHAR )
1412+ + ' use ' + grps2 .data_compression_desc
1413+ ELSE ' '
1414+ + CAST ([grps2].[MinKey] AS VARCHAR )
1415+ + ' uses ' + grps2 .data_compression_desc
1416+ END AS [Partitions]
1417+ FROM [grps] AS grps2
1418+ WHERE grps2 .index_sanity_id = grps .index_sanity_id
1419+ ORDER BY grps2 .MinKey , grps2 .MaxKey
1420+ FOR XML PATH (' ' ) ,
1421+ TYPE
1422+ ).[value](' .' , ' VARCHAR(MAX)' ), 1 , 1 , ' ' ) ), 0 , 8000 ) AS [partition_compression_detail]
1423+ FROM grps;
1424+
1425+ UPDATE sz
1426+ SET sz .data_compression_desc = pci .partition_compression_detail
1427+ FROM #IndexSanitySize sz
1428+ JOIN #PartitionCompressionInfo AS pci
1429+ ON pci .index_sanity_id = sz .index_sanity_id ;
1430+
1431+
1432+
1433+
13821434 IF ((PARSENAME (@SQLServerProductVersion, 4 ) >= 12 )
13831435 OR (PARSENAME (@SQLServerProductVersion, 4 ) = 11 AND PARSENAME (@SQLServerProductVersion, 2 ) >= 3000 )
13841436 OR (PARSENAME (@SQLServerProductVersion, 4 ) = 10 AND PARSENAME (@SQLServerProductVersion, 3 ) = 50 AND PARSENAME (@SQLServerProductVersion, 2 ) >= 2500 ))
@@ -1540,12 +1592,12 @@ BEGIN
15401592 SELECT DISTINCT grps .index_sanity_id , SUBSTRING (( STUFF ((SELECT ' , ' + ' Partition'
15411593 + CASE WHEN [grps2].[MinKey] < [grps2].[MaxKey]
15421594 THEN + ' s '
1543- + CAST ([grps2].[MinKey] AS VARCHAR )
1595+ + CAST ([grps2].[MinKey] AS VARCHAR ( 100 ) )
15441596 + ' - '
1545- + CAST ([grps2].[MaxKey] AS VARCHAR )
1597+ + CAST ([grps2].[MaxKey] AS VARCHAR ( 100 ) )
15461598 + ' use ' + grps2 .data_compression_desc
15471599 ELSE ' '
1548- + CAST ([grps2].[MinKey] AS VARCHAR )
1600+ + CAST ([grps2].[MinKey] AS VARCHAR ( 100 ) )
15491601 + ' uses ' + grps2 .data_compression_desc
15501602 END AS [Partitions]
15511603 FROM [grps] AS grps2
@@ -1763,7 +1815,8 @@ BEGIN;
17631815 FROM #IndexSanity
17641816 WHERE index_type IN (1 ,2 ) /* Clustered, NC only*/
17651817 AND is_hypothetical= 0
1766- AND is_disabled= 0 )
1818+ AND is_disabled= 0
1819+ AND is_primary_key = 0 )
17671820 INSERT #BlitzIndexResults ( check_id, index_sanity_id, Priority, findings_group, finding, [database_name], URL , details, index_definition,
17681821 secret_columns, index_usage_summary, index_size_summary )
17691822 SELECT 2 AS check_id,
@@ -1788,6 +1841,7 @@ BEGIN;
17881841 di .key_column_names <> ip .key_column_names AND
17891842 di .number_dupes > 1
17901843 )
1844+ AND ip .is_primary_key = 0
17911845 /* WHERE clause skips near-duplicate indexes when getting all databases or using PainRelief mode */
17921846 AND NOT (@GetAllDatabases = 1 OR @Mode = 0 )
17931847
@@ -3093,7 +3147,8 @@ BEGIN;
30933147 LEFT JOIN #IndexCreateTsql ts ON
30943148 br .index_sanity_id = ts .index_sanity_id
30953149 WHERE br .check_id IN (0 , 1 , 11 , 22 , 43 , 68 , 50 , 60 , 61 , 62 , 63 , 64 , 65 )
3096- ORDER BY Priority, br .findings_group , br .finding , ISNULL (SUBSTRING (br .details , CHARINDEX (' : ' , br .details ) + 2 , LEN (br .details ) - CHARINDEX (' : ' , br .details )), 0 ) DESC , br .database_name ASC , [check_id] ASC , blitz_result_id ASC ;
3150+ ORDER BY br .Priority ASC , br .check_id ASC , br .blitz_result_id ASC , br .findings_group ASC
3151+ OPTION (RECOMPILE );
30973152
30983153 END
30993154 ELSE IF (@Mode = 4 )
@@ -3114,7 +3169,8 @@ BEGIN;
31143169 br .index_sanity_id = sn .index_sanity_id
31153170 LEFT JOIN #IndexCreateTsql ts ON
31163171 br .index_sanity_id = ts .index_sanity_id
3117- ORDER BY Priority, br .findings_group , br .finding , ISNULL (SUBSTRING (br .details , CHARINDEX (' : ' , br .details ) + 2 , LEN (br .details ) - CHARINDEX (' : ' , br .details )), 0 ) DESC , br .database_name ASC , [check_id] ASC , blitz_result_id ASC ;
3172+ ORDER BY br .Priority ASC , br .check_id ASC , br .blitz_result_id ASC , br .findings_group ASC
3173+ OPTION (RECOMPILE );
31183174
31193175 END ; /* End @Mode=0 or 4 (diagnose)*/
31203176 ELSE IF @Mode= 1 /* Summarize*/
@@ -3287,6 +3343,7 @@ BEGIN;
32873343 NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,
32883344 NULL , 0 AS display_order
32893345 ORDER BY [Display Order] ASC , [Magic Benefit Number] DESC
3346+ OPTION (RECOMPILE );
32903347
32913348 END /* End @Mode=3 (index detail)*/
32923349END
0 commit comments