From 79b2a0026bd54ef9bb6a43d48044d32418b706fd Mon Sep 17 00:00:00 2001 From: Andrew Lund Date: Thu, 3 Apr 2025 17:17:19 +0200 Subject: [PATCH 1/2] Compression eligibility changes --- sp_IndexCleanup/sp_IndexCleanup.sql | 41 ++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 3 deletions(-) diff --git a/sp_IndexCleanup/sp_IndexCleanup.sql b/sp_IndexCleanup/sp_IndexCleanup.sql index 4b6a6b5b..37a97895 100644 --- a/sp_IndexCleanup/sp_IndexCleanup.sql +++ b/sp_IndexCleanup/sp_IndexCleanup.sql @@ -1408,9 +1408,45 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ce SET ce.can_compress = 0, - ce.reason = ''Table contains sparse columns or incompatible data types'' + ce.reason = ''Table contains sparse columns'' FROM #compression_eligibility AS ce WHERE EXISTS + ( + SELECT + 1/0 + FROM ' + QUOTENAME(@current_database_name) + N'.sys.columns AS c + WHERE c.object_id = ce.object_id + AND + ( + c.is_sparse = 1 + ) + ) + OPTION(RECOMPILE); + '; + + IF @debug = 1 + BEGIN + PRINT @sql; + END; + + EXECUTE sys.sp_executesql + @sql; + + SELECT + @sql = N' + SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED; + + UPDATE + ce + SET + ce.can_compress = 0, + ce.reason = ''Index contains incompatible data types'' + FROM #compression_eligibility AS ce + JOIN sys.indexes AS i + ON i.object_id = ce.object_id AND i.index_id = ce.index_id + WHERE ce.can_compress = 1 + AND i.type = 1 + AND EXISTS ( SELECT 1/0 @@ -1420,8 +1456,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. WHERE c.object_id = ce.object_id AND ( - c.is_sparse = 1 - OR t.name IN (N''text'', N''ntext'', N''image'') + t.name IN (N''text'', N''ntext'', N''image'') ) ) OPTION(RECOMPILE); From c0d30fc7f2b3a6f6463ef1e744734cfb1c125163 Mon Sep 17 00:00:00 2001 From: Andrew Lund Date: Thu, 3 Apr 2025 17:26:52 +0200 Subject: [PATCH 2/2] Missing quote name --- 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 37a97895..581c7a93 100644 --- a/sp_IndexCleanup/sp_IndexCleanup.sql +++ b/sp_IndexCleanup/sp_IndexCleanup.sql @@ -1442,7 +1442,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ce.can_compress = 0, ce.reason = ''Index contains incompatible data types'' FROM #compression_eligibility AS ce - JOIN sys.indexes AS i + JOIN ' + QUOTENAME(@current_database_name) + N'.sys.indexes AS i ON i.object_id = ce.object_id AND i.index_id = ce.index_id WHERE ce.can_compress = 1 AND i.type = 1