Skip to content

Commit

Permalink
Merge pull request #3295 from BrentOzarULTD/3294_sp_BlitzIndex_more_c…
Browse files Browse the repository at this point in the history
…olumnstore

#3294 sp_BlitzIndex columnstore
  • Loading branch information
BrentOzar authored Aug 15, 2023
2 parents 05f99cc + 4bb9866 commit 2077906
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions sp_BlitzIndex.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2958,7 +2958,8 @@ BEGIN
+ CASE WHEN @ShowPartitionRanges = 1 THEN N' COALESCE(range_start_op + '' '' + range_start + '' '', '''') + COALESCE(range_end_op + '' '' + range_end, '''') AS partition_range, ' ELSE N' ' END
+ N' row_group_id, total_rows, deleted_rows, '
+ @ColumnList
+ CASE WHEN @ShowPartitionRanges = 1 THEN N'
+ CASE WHEN @ShowPartitionRanges = 1 THEN N' ,
state_desc, trim_reason_desc, transition_to_compressed_state_desc, has_vertipaq_optimization
FROM (
SELECT column_name, partition_number, row_group_id, total_rows, deleted_rows, details,
range_start_op,
Expand All @@ -2968,10 +2969,12 @@ BEGIN
range_end_op,
CASE
WHEN format_type IS NULL THEN CAST(range_end_value AS NVARCHAR(4000))
ELSE CONVERT(NVARCHAR(4000), range_end_value, format_type) END range_end' ELSE N' ' END + N'
ELSE CONVERT(NVARCHAR(4000), range_end_value, format_type) END range_end' ELSE N' ' END + N',
state_desc, trim_reason_desc, transition_to_compressed_state_desc, has_vertipaq_optimization
FROM (
SELECT c.name AS column_name, p.partition_number, rg.row_group_id, rg.total_rows, rg.deleted_rows,
details = CAST(seg.min_data_id AS VARCHAR(20)) + '' to '' + CAST(seg.max_data_id AS VARCHAR(20)) + '', '' + CAST(CAST((seg.on_disk_size / 1024.0 / 1024) AS DECIMAL(18,0)) AS VARCHAR(20)) + '' MB'''
phys.state_desc, phys.trim_reason_desc, phys.transition_to_compressed_state_desc, phys.has_vertipaq_optimization,
details = CAST(seg.min_data_id AS VARCHAR(20)) + '' to '' + CAST(seg.max_data_id AS VARCHAR(20)) + '', '' + CAST(CAST(((COALESCE(d.on_disk_size,0) + COALESCE(seg.on_disk_size,0)) / 1024.0 / 1024) AS DECIMAL(18,0)) AS VARCHAR(20)) + '' MB'''
+ CASE WHEN @ShowPartitionRanges = 1 THEN N',
CASE
WHEN pp.system_type_id IN (40, 41, 42, 43, 58, 61) THEN 126
Expand All @@ -2985,14 +2988,16 @@ BEGIN
FROM ' + QUOTENAME(@DatabaseName) + N'.sys.column_store_row_groups rg
INNER JOIN ' + QUOTENAME(@DatabaseName) + N'.sys.columns c ON rg.object_id = c.object_id
INNER JOIN ' + QUOTENAME(@DatabaseName) + N'.sys.partitions p ON rg.object_id = p.object_id AND rg.partition_number = p.partition_number
INNER JOIN ' + QUOTENAME(@DatabaseName) + N'.sys.index_columns ic on ic.column_id = c.column_id AND ic.object_id = c.object_id AND ic.index_id = p.index_id ' + CASE WHEN @ShowPartitionRanges = 1 THEN N'
INNER JOIN ' + QUOTENAME(@DatabaseName) + N'.sys.index_columns ic on ic.column_id = c.column_id AND ic.object_id = c.object_id AND ic.index_id = p.index_id
LEFT OUTER JOIN ' + QUOTENAME(@DatabaseName) + N'.sys.dm_db_column_store_row_group_physical_stats phys ON rg.row_group_id = phys.row_group_id AND rg.object_id = phys.object_id AND rg.partition_number = phys.partition_number AND p.index_id = phys.index_id ' + CASE WHEN @ShowPartitionRanges = 1 THEN N'
LEFT OUTER JOIN ' + QUOTENAME(@DatabaseName) + N'.sys.indexes i ON i.object_id = rg.object_id AND i.index_id = rg.index_id
LEFT OUTER JOIN ' + QUOTENAME(@DatabaseName) + N'.sys.partition_schemes ps ON ps.data_space_id = i.data_space_id
LEFT OUTER JOIN ' + QUOTENAME(@DatabaseName) + N'.sys.partition_functions pf ON pf.function_id = ps.function_id
LEFT OUTER JOIN ' + QUOTENAME(@DatabaseName) + N'.sys.partition_parameters pp ON pp.function_id = pf.function_id
LEFT OUTER JOIN ' + QUOTENAME(@DatabaseName) + N'.sys.partition_range_values prvs ON prvs.function_id = pf.function_id AND prvs.boundary_id = p.partition_number - 1
LEFT OUTER JOIN ' + QUOTENAME(@DatabaseName) + N'.sys.partition_range_values prve ON prve.function_id = pf.function_id AND prve.boundary_id = p.partition_number ' ELSE N' ' END
+ N' LEFT OUTER JOIN ' + QUOTENAME(@DatabaseName) + N'.sys.column_store_segments seg ON p.partition_id = seg.partition_id AND ic.index_column_id = seg.column_id AND rg.row_group_id = seg.segment_id
LEFT OUTER JOIN ' + QUOTENAME(@DatabaseName) + N'.sys.column_store_dictionaries d ON p.hobt_id = d.hobt_id AND c.column_id = d.column_id AND seg.secondary_dictionary_id = d.dictionary_id
WHERE rg.object_id = @ObjectID
AND rg.state IN (1, 2, 3)
AND c.name IN ( ' + @ColumnListWithApostrophes + N')'
Expand Down Expand Up @@ -3030,6 +3035,9 @@ BEGIN
RAISERROR(N'Done visualizing columnstore index contents.', 0,1) WITH NOWAIT;
END

IF @ShowColumnstoreOnly = 1
RETURN;

END; /* IF @TableName IS NOT NULL */


Expand Down

0 comments on commit 2077906

Please sign in to comment.