Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Query all table data and index compression

Tags:

Does anyone happen to have a generic SQL statement that'll list all of the tables and indexes in a database, along with their current compression setting, for each partition?

Thanks.

EDIT: This is as far as I got in my attempt to query tables, but I'm not sure the join is correct (I'm getting duplicates, which seems to be caused by the presence of indexes)

SELECT [t].[name], [p].[partition_number], [p].[data_compression_desc] FROM [sys].[partitions] AS [p] INNER JOIN sys.tables AS [t] ON [t].[object_id] = [p].[object_id] 
like image 566
Barguast Avatar asked Jun 07 '13 15:06

Barguast


People also ask

How do you check compression on a table?

To check the Compression ratio for a table, you can navigate to Table Definition. Go to Runtime Information. To see Compression Ratio, go to Columns tab. You can see the compression ratio in the Main Size Compression Ratio [%] column.

How do you check if a SQL table is compressed?

In SQL Server, you can query the sys. partitions system catalog view to find out whether or not a partition has been compressed. In particular, the data_compression column tells you whether it's compressed or not. The data_compression_desc column tells you what type of compression it uses.

How do I compress an index in SQL?

To compress an index, expand the table that contains the index that you want to compress and then expand the Indexes folder. Right-click the table or index to compress, point to Storage and select Manage Compression.... In the Data Compression Wizard, on the Welcome to the Data Compression Wizard page, select Next.


1 Answers

I thought I'd share my final query. This'll give two result sets, the first of data compression for heaps and clustered indexes, and the second of index compression for non-clustered indexes.

SELECT [t].[name] AS [Table], [p].[partition_number] AS [Partition],     [p].[data_compression_desc] AS [Compression] FROM [sys].[partitions] AS [p] INNER JOIN sys.tables AS [t] ON [t].[object_id] = [p].[object_id] WHERE [p].[index_id] in (0,1)  SELECT [t].[name] AS [Table], [i].[name] AS [Index],       [p].[partition_number] AS [Partition],     [p].[data_compression_desc] AS [Compression] FROM [sys].[partitions] AS [p] INNER JOIN sys.tables AS [t] ON [t].[object_id] = [p].[object_id] INNER JOIN sys.indexes AS [i] ON [i].[object_id] = [p].[object_id] AND [i].[index_id] = [p].[index_id] WHERE [p].[index_id] > 1 
like image 136
Barguast Avatar answered Sep 27 '22 18:09

Barguast