Skip to content

Commit dbefa60

Browse files
1.0.3 Partial Update 3
New functionality: Row Groups Details (ad-hoc & stored proc)
1 parent a80cef2 commit dbefa60

6 files changed

+420
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
Columnstore Indexes Scripts Library for Azure SQLDatabase:
3+
Row Groups Details - Shows detailed information on the Columnstore Row Groups
4+
Version: 1.0.3, November 2015
5+
6+
Copyright 2015 Niko Neugebauer, OH22 IS (http://www.nikoport.com/columnstore/), (http://www.oh22.is/)
7+
8+
Licensed under the Apache License, Version 2.0 (the "License");
9+
you may not use this file except in compliance with the License.
10+
You may obtain a copy of the License at
11+
12+
http://www.apache.org/licenses/LICENSE-2.0
13+
14+
Unless required by applicable law or agreed to in writing, software
15+
distributed under the License is distributed on an "AS IS" BASIS,
16+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
See the License for the specific language governing permissions and
18+
limitations under the License.
19+
*/
20+
21+
declare @SQLServerVersion nvarchar(128) = cast(SERVERPROPERTY('ProductVersion') as NVARCHAR(128)),
22+
@SQLServerEdition nvarchar(128) = cast(SERVERPROPERTY('Edition') as NVARCHAR(128));
23+
declare @errorMessage nvarchar(512);
24+
25+
-- Ensure that we are running Azure SQLDatabase
26+
if SERVERPROPERTY('EngineEdition') <> 5
27+
begin
28+
set @errorMessage = (N'Your are not running this script agains Azure SQLDatabase: Your are running a ' + @SQLServerEdition);
29+
Throw 51000, @errorMessage, 1;
30+
end
31+
32+
--------------------------------------------------------------------------------------------------------------------
33+
if EXISTS (select * from sys.objects where type = 'p' and name = 'cstore_GetRowGroupsDetails' and schema_id = SCHEMA_ID('dbo') )
34+
Drop Procedure dbo.cstore_GetRowGroupsDetails;
35+
GO
36+
37+
create procedure dbo.cstore_GetRowGroupsDetails(
38+
-- Params --
39+
@schemaName nvarchar(256) = NULL, -- Allows to show data filtered down to the specified schema
40+
@tableName nvarchar(256) = NULL, -- Allows to show data filtered down to the specified table name
41+
@partitionNumber bigint = 0, -- Allows to show details of each of the available partitions, where 0 stands for no filtering
42+
@showTrimmedGroupsOnly bit = 0, -- Filters only those Row Groups, which size <> 1048576
43+
@showNonCompressedOnly bit = 0, -- Filters out the comrpessed Row Groups
44+
@showFragmentedGroupsOnly bit = 0, -- Allows to show the Row Groups that have Deleted Rows in them
45+
@minSizeInMB Decimal(16,3) = NULL, -- Minimum size in MB for a table to be included
46+
@maxSizeInMB Decimal(16,3) = NULL -- Maximum size in MB for a table to be included
47+
-- end of --
48+
) as
49+
BEGIN
50+
set nocount on;
51+
52+
select quotename(object_schema_name(rg.object_id)) + '.' + quotename(object_name(rg.object_id)) as [Table Name],
53+
rg.partition_number,
54+
rg.row_group_id,
55+
rg.state,
56+
rg.state_description,
57+
rg.total_rows,
58+
rg.deleted_rows,
59+
cast(isnull(rg.size_in_bytes,0) / 1024. / 1024 as Decimal(8,3)) as [Size in MB]
60+
from sys.column_store_row_groups rg
61+
where rg.total_rows <> case @showTrimmedGroupsOnly when 1 then 1048576 else -1 end
62+
and rg.state <> case @showNonCompressedOnly when 0 then -1 else 3 end
63+
and isnull(rg.deleted_rows,0) <> case @showFragmentedGroupsOnly when 1 then 0 else -1 end
64+
and (@tableName is null or object_name (rg.object_id) like '%' + @tableName + '%')
65+
and (@schemaName is null or object_schema_name(rg.object_id) = @schemaName)
66+
and rg.partition_number = case @partitionNumber when 0 then rg.partition_number else @partitionNumber end
67+
and cast(isnull(rg.size_in_bytes,0) / 1024. / 1024 as Decimal(8,3)) >= isnull(@minSizeInMB,0.)
68+
and cast(isnull(rg.size_in_bytes,0) / 1024. / 1024 as Decimal(8,3)) <= isnull(@maxSizeInMB,999999999.)
69+
order by quotename(object_schema_name(rg.object_id)) + '.' + quotename(object_name(rg.object_id)), rg.row_group_id;
70+
END

Azure/row_groups_details.sql

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
Columnstore Indexes Scripts Library for Azure SQLDatabase:
3+
Row Groups Details - Shows detailed information on the Columnstore Row Groups
4+
Version: 1.0.3, November 2015
5+
6+
Copyright 2015 Niko Neugebauer, OH22 IS (http://www.nikoport.com/columnstore/), (http://www.oh22.is/)
7+
8+
Licensed under the Apache License, Version 2.0 (the "License");
9+
you may not use this file except in compliance with the License.
10+
You may obtain a copy of the License at
11+
12+
http://www.apache.org/licenses/LICENSE-2.0
13+
14+
Unless required by applicable law or agreed to in writing, software
15+
distributed under the License is distributed on an "AS IS" BASIS,
16+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
See the License for the specific language governing permissions and
18+
limitations under the License.
19+
*/
20+
21+
-- Params --
22+
declare @schemaName nvarchar(256) = NULL, -- Allows to show data filtered down to the specified schema
23+
@tableName nvarchar(256) = NULL, -- Allows to show data filtered down to the specified table name
24+
@partitionNumber bigint = 0, -- Allows to show details of each of the available partitions, where 0 stands for no filtering
25+
@showTrimmedGroupsOnly bit = 0, -- Filters only those Row Groups, which size <> 1048576
26+
@showNonCompressedOnly bit = 0, -- Filters out the comrpessed Row Groups
27+
@showFragmentedGroupsOnly bit = 0, -- Allows to show the Row Groups that have Deleted Rows in them
28+
@minSizeInMB Decimal(16,3) = NULL, -- Minimum size in MB for a table to be included
29+
@maxSizeInMB Decimal(16,3) = NULL -- Maximum size in MB for a table to be included
30+
-- end of --
31+
32+
declare @SQLServerVersion nvarchar(128) = cast(SERVERPROPERTY('ProductVersion') as NVARCHAR(128)),
33+
@SQLServerEdition nvarchar(128) = cast(SERVERPROPERTY('Edition') as NVARCHAR(128));
34+
declare @errorMessage nvarchar(512);
35+
36+
-- Ensure that we are running Azure SQLDatabase
37+
if SERVERPROPERTY('EngineEdition') <> 5
38+
begin
39+
set @errorMessage = (N'Your are not running this script agains Azure SQLDatabase: Your are running a ' + @SQLServerEdition);
40+
Throw 51000, @errorMessage, 1;
41+
end
42+
43+
set nocount on;
44+
45+
select quotename(object_schema_name(rg.object_id)) + '.' + quotename(object_name(rg.object_id)) as [Table Name],
46+
rg.partition_number,
47+
rg.row_group_id,
48+
rg.state,
49+
rg.state_description,
50+
rg.total_rows,
51+
rg.deleted_rows,
52+
cast(isnull(rg.size_in_bytes,0) / 1024. / 1024 as Decimal(8,3)) as [Size in MB]
53+
from sys.column_store_row_groups rg
54+
where rg.total_rows <> case @showTrimmedGroupsOnly when 1 then 1048576 else -1 end
55+
and rg.state <> case @showNonCompressedOnly when 0 then -1 else 3 end
56+
and isnull(rg.deleted_rows,0) <> case @showFragmentedGroupsOnly when 1 then 0 else -1 end
57+
and (@tableName is null or object_name (rg.object_id) like '%' + @tableName + '%')
58+
and (@schemaName is null or object_schema_name(rg.object_id) = @schemaName)
59+
and rg.partition_number = case @partitionNumber when 0 then rg.partition_number else @partitionNumber end
60+
and cast(isnull(rg.size_in_bytes,0) / 1024. / 1024 as Decimal(8,3)) >= isnull(@minSizeInMB,0.)
61+
and cast(isnull(rg.size_in_bytes,0) / 1024. / 1024 as Decimal(8,3)) <= isnull(@maxSizeInMB,999999999.)
62+
order by quotename(object_schema_name(rg.object_id)) + '.' + quotename(object_name(rg.object_id)), rg.row_group_id
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/*
2+
Columnstore Indexes Scripts Library for SQL Server 2014:
3+
Row Groups Details - Shows detailed information on the Columnstore Row Groups
4+
Version: 1.0.3, November 2015
5+
6+
Copyright 2015 Niko Neugebauer, OH22 IS (http://www.nikoport.com/columnstore/), (http://www.oh22.is/)
7+
8+
Licensed under the Apache License, Version 2.0 (the "License");
9+
you may not use this file except in compliance with the License.
10+
You may obtain a copy of the License at
11+
12+
http://www.apache.org/licenses/LICENSE-2.0
13+
14+
Unless required by applicable law or agreed to in writing, software
15+
distributed under the License is distributed on an "AS IS" BASIS,
16+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
See the License for the specific language governing permissions and
18+
limitations under the License.
19+
*/
20+
21+
declare @SQLServerVersion nvarchar(128) = cast(SERVERPROPERTY('ProductVersion') as NVARCHAR(128)),
22+
@SQLServerEdition nvarchar(128) = cast(SERVERPROPERTY('Edition') as NVARCHAR(128));
23+
declare @errorMessage nvarchar(512);
24+
25+
--Ensure that we are running SQL Server 2014
26+
if substring(@SQLServerVersion,1,CHARINDEX('.',@SQLServerVersion)-1) <> N'12'
27+
begin
28+
set @errorMessage = (N'You are not running a SQL Server 2014. Your SQL Server version is ' + @SQLServerVersion);
29+
Throw 51000, @errorMessage, 1;
30+
end
31+
32+
if SERVERPROPERTY('EngineEdition') <> 3
33+
begin
34+
set @errorMessage = (N'Your SQL Server 2014 Edition is not an Enterprise or a Developer Edition: Your are running a ' + @SQLServerEdition);
35+
Throw 51000, @errorMessage, 1;
36+
end
37+
38+
--------------------------------------------------------------------------------------------------------------------
39+
if EXISTS (select * from sys.objects where type = 'p' and name = 'cstore_GetRowGroupsDetails' and schema_id = SCHEMA_ID('dbo') )
40+
Drop Procedure dbo.cstore_GetRowGroupsDetails;
41+
GO
42+
43+
create procedure dbo.cstore_GetRowGroupsDetails(
44+
-- Params --
45+
@schemaName nvarchar(256) = NULL, -- Allows to show data filtered down to the specified schema
46+
@tableName nvarchar(256) = NULL, -- Allows to show data filtered down to the specified table name
47+
@partitionNumber bigint = 0, -- Allows to show details of each of the available partitions, where 0 stands for no filtering
48+
@showTrimmedGroupsOnly bit = 0, -- Filters only those Row Groups, which size <> 1048576
49+
@showNonCompressedOnly bit = 0, -- Filters out the comrpessed Row Groups
50+
@showFragmentedGroupsOnly bit = 0, -- Allows to show the Row Groups that have Deleted Rows in them
51+
@minSizeInMB Decimal(16,3) = NULL, -- Minimum size in MB for a table to be included
52+
@maxSizeInMB Decimal(16,3) = NULL -- Maximum size in MB for a table to be included
53+
-- end of --
54+
) as
55+
BEGIN
56+
set nocount on;
57+
58+
select quotename(object_schema_name(rg.object_id)) + '.' + quotename(object_name(rg.object_id)) as [Table Name],
59+
rg.partition_number,
60+
rg.row_group_id,
61+
rg.state,
62+
rg.state_description,
63+
rg.total_rows,
64+
rg.deleted_rows,
65+
cast(isnull(rg.size_in_bytes,0) / 1024. / 1024 as Decimal(8,3)) as [Size in MB]
66+
from sys.column_store_row_groups rg
67+
where rg.total_rows <> case @showTrimmedGroupsOnly when 1 then 1048576 else -1 end
68+
and rg.state <> case @showNonCompressedOnly when 0 then -1 else 3 end
69+
and isnull(rg.deleted_rows,0) <> case @showFragmentedGroupsOnly when 1 then 0 else -1 end
70+
and (@tableName is null or object_name (rg.object_id) like '%' + @tableName + '%')
71+
and (@schemaName is null or object_schema_name(rg.object_id) = @schemaName)
72+
and rg.partition_number = case @partitionNumber when 0 then rg.partition_number else @partitionNumber end
73+
and cast(isnull(rg.size_in_bytes,0) / 1024. / 1024 as Decimal(8,3)) >= isnull(@minSizeInMB,0.)
74+
and cast(isnull(rg.size_in_bytes,0) / 1024. / 1024 as Decimal(8,3)) <= isnull(@maxSizeInMB,999999999.)
75+
order by quotename(object_schema_name(rg.object_id)) + '.' + quotename(object_name(rg.object_id)), rg.row_group_id;
76+
END

SQL-2014/row_groups_details.sql

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
Columnstore Indexes Scripts Library for SQL Server 2014:
3+
Row Groups Details - Shows detailed information on the Columnstore Row Groups
4+
Version: 1.0.3, November 2015
5+
6+
Copyright 2015 Niko Neugebauer, OH22 IS (http://www.nikoport.com/columnstore/), (http://www.oh22.is/)
7+
8+
Licensed under the Apache License, Version 2.0 (the "License");
9+
you may not use this file except in compliance with the License.
10+
You may obtain a copy of the License at
11+
12+
http://www.apache.org/licenses/LICENSE-2.0
13+
14+
Unless required by applicable law or agreed to in writing, software
15+
distributed under the License is distributed on an "AS IS" BASIS,
16+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
See the License for the specific language governing permissions and
18+
limitations under the License.
19+
*/
20+
21+
-- Params --
22+
declare @schemaName nvarchar(256) = NULL, -- Allows to show data filtered down to the specified schema
23+
@tableName nvarchar(256) = NULL, -- Allows to show data filtered down to the specified table name
24+
@partitionNumber bigint = 0, -- Allows to show details of each of the available partitions, where 0 stands for no filtering
25+
@showTrimmedGroupsOnly bit = 0, -- Filters only those Row Groups, which size <> 1048576
26+
@showNonCompressedOnly bit = 0, -- Filters out the comrpessed Row Groups
27+
@showFragmentedGroupsOnly bit = 0, -- Allows to show the Row Groups that have Deleted Rows in them
28+
@minSizeInMB Decimal(16,3) = NULL, -- Minimum size in MB for a table to be included
29+
@maxSizeInMB Decimal(16,3) = NULL -- Maximum size in MB for a table to be included
30+
-- end of --
31+
32+
declare @SQLServerVersion nvarchar(128) = cast(SERVERPROPERTY('ProductVersion') as NVARCHAR(128)),
33+
@SQLServerEdition nvarchar(128) = cast(SERVERPROPERTY('Edition') as NVARCHAR(128));
34+
declare @errorMessage nvarchar(512);
35+
36+
--Ensure that we are running SQL Server 2014
37+
if substring(@SQLServerVersion,1,CHARINDEX('.',@SQLServerVersion)-1) <> N'12'
38+
begin
39+
set @errorMessage = (N'You are not running a SQL Server 2014. Your SQL Server version is ' + @SQLServerVersion);
40+
Throw 51000, @errorMessage, 1;
41+
end
42+
43+
if SERVERPROPERTY('EngineEdition') <> 3
44+
begin
45+
set @errorMessage = (N'Your SQL Server 2014 Edition is not an Enterprise or a Developer Edition: Your are running a ' + @SQLServerEdition);
46+
Throw 51000, @errorMessage, 1;
47+
end
48+
49+
set nocount on;
50+
51+
select quotename(object_schema_name(rg.object_id)) + '.' + quotename(object_name(rg.object_id)) as [Table Name],
52+
rg.partition_number,
53+
rg.row_group_id,
54+
rg.state,
55+
rg.state_description,
56+
rg.total_rows,
57+
rg.deleted_rows,
58+
cast(isnull(rg.size_in_bytes,0) / 1024. / 1024 as Decimal(8,3)) as [Size in MB]
59+
from sys.column_store_row_groups rg
60+
where rg.total_rows <> case @showTrimmedGroupsOnly when 1 then 1048576 else -1 end
61+
and rg.state <> case @showNonCompressedOnly when 0 then -1 else 3 end
62+
and isnull(rg.deleted_rows,0) <> case @showFragmentedGroupsOnly when 1 then 0 else -1 end
63+
and (@tableName is null or object_name (rg.object_id) like '%' + @tableName + '%')
64+
and (@schemaName is null or object_schema_name(rg.object_id) = @schemaName)
65+
and rg.partition_number = case @partitionNumber when 0 then rg.partition_number else @partitionNumber end
66+
and cast(isnull(rg.size_in_bytes,0) / 1024. / 1024 as Decimal(8,3)) >= isnull(@minSizeInMB,0.)
67+
and cast(isnull(rg.size_in_bytes,0) / 1024. / 1024 as Decimal(8,3)) <= isnull(@maxSizeInMB,999999999.)
68+
order by quotename(object_schema_name(rg.object_id)) + '.' + quotename(object_name(rg.object_id)), rg.row_group_id
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/*
2+
Columnstore Indexes Scripts Library for SQL Server 2016:
3+
Row Groups Details - Shows detailed information on the Columnstore Row Groups
4+
Version: 1.0.3, November 2015
5+
6+
Copyright 2015 Niko Neugebauer, OH22 IS (http://www.nikoport.com/columnstore/), (http://www.oh22.is/)
7+
8+
Licensed under the Apache License, Version 2.0 (the "License");
9+
you may not use this file except in compliance with the License.
10+
You may obtain a copy of the License at
11+
12+
http://www.apache.org/licenses/LICENSE-2.0
13+
14+
Unless required by applicable law or agreed to in writing, software
15+
distributed under the License is distributed on an "AS IS" BASIS,
16+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
See the License for the specific language governing permissions and
18+
limitations under the License.
19+
*/
20+
21+
declare @SQLServerVersion nvarchar(128) = cast(SERVERPROPERTY('ProductVersion') as NVARCHAR(128)),
22+
@SQLServerEdition nvarchar(128) = cast(SERVERPROPERTY('Edition') as NVARCHAR(128));
23+
declare @errorMessage nvarchar(512);
24+
25+
-- --Ensure that we are running SQL Server 2016
26+
if substring(@SQLServerVersion,1,CHARINDEX('.',@SQLServerVersion)-1) <> N'13'
27+
begin
28+
set @errorMessage = (N'You are not running a SQL Server 2016. Your SQL Server version is ' + @SQLServerVersion);
29+
Throw 51000, @errorMessage, 1;
30+
end
31+
32+
if SERVERPROPERTY('EngineEdition') <> 3
33+
begin
34+
set @errorMessage = (N'Your SQL Server 2016 Edition is not an Enterprise or a Developer Edition: Your are running a ' + @SQLServerEdition);
35+
Throw 51000, @errorMessage, 1;
36+
end
37+
38+
--------------------------------------------------------------------------------------------------------------------
39+
if EXISTS (select * from sys.objects where type = 'p' and name = 'cstore_GetRowGroupsDetails' and schema_id = SCHEMA_ID('dbo') )
40+
Drop Procedure dbo.cstore_GetRowGroupsDetails;
41+
GO
42+
43+
create procedure dbo.cstore_GetRowGroupsDetails(
44+
-- Params --
45+
@schemaName nvarchar(256) = NULL, -- Allows to show data filtered down to the specified schema
46+
@tableName nvarchar(256) = NULL, -- Allows to show data filtered down to the specified table name
47+
@partitionNumber bigint = 0, -- Allows to show details of each of the available partitions, where 0 stands for no filtering
48+
@showTrimmedGroupsOnly bit = 0, -- Filters only those Row Groups, which size <> 1048576
49+
@showNonCompressedOnly bit = 0, -- Filters out the comrpessed Row Groups
50+
@showFragmentedGroupsOnly bit = 0, -- Allows to show the Row Groups that have Deleted Rows in them
51+
@minSizeInMB Decimal(16,3) = NULL, -- Minimum size in MB for a table to be included
52+
@maxSizeInMB Decimal(16,3) = NULL -- Maximum size in MB for a table to be included
53+
-- end of --
54+
) as
55+
BEGIN
56+
set nocount on;
57+
58+
select quotename(object_schema_name(rg.object_id)) + '.' + quotename(object_name(rg.object_id)) as [Table Name],
59+
rg.partition_number,
60+
rg.row_group_id,
61+
rg.state,
62+
rg.state_description,
63+
rg.total_rows,
64+
rg.deleted_rows,
65+
cast(isnull(rg.size_in_bytes,0) / 1024. / 1024 as Decimal(8,3)) as [Size in MB]
66+
from sys.column_store_row_groups rg
67+
where rg.total_rows <> case @showTrimmedGroupsOnly when 1 then 1048576 else -1 end
68+
and rg.state <> case @showNonCompressedOnly when 0 then -1 else 3 end
69+
and isnull(rg.deleted_rows,0) <> case @showFragmentedGroupsOnly when 1 then 0 else -1 end
70+
and (@tableName is null or object_name (rg.object_id) like '%' + @tableName + '%')
71+
and (@schemaName is null or object_schema_name(rg.object_id) = @schemaName)
72+
and rg.partition_number = case @partitionNumber when 0 then rg.partition_number else @partitionNumber end
73+
and cast(isnull(rg.size_in_bytes,0) / 1024. / 1024 as Decimal(8,3)) >= isnull(@minSizeInMB,0.)
74+
and cast(isnull(rg.size_in_bytes,0) / 1024. / 1024 as Decimal(8,3)) <= isnull(@maxSizeInMB,999999999.)
75+
order by quotename(object_schema_name(rg.object_id)) + '.' + quotename(object_name(rg.object_id)), rg.row_group_id;
76+
END

0 commit comments

Comments
 (0)