1
1
/*
2
2
CSIL - Columnstore Indexes Scripts Library for SQL Server 2016:
3
3
Columnstore Alignment - Shows the alignment (ordering) between the different Columnstore Segments
4
- Version: 1.4.1, November 2016
4
+ Version: 1.4.2, December 2016
5
5
6
6
Copyright 2015-2016 Niko Neugebauer, OH22 IS (http://www.nikoport.com/columnstore/), (http://www.oh22.is/)
7
7
58
58
59
59
60
60
-- ------------------------------------------------------------------------------------------------------------------
61
- IF NOT EXISTS (select * from sys .objects where type = ' p' and name = ' cstore_GetAlignment' and schema_id = SCHEMA_ID (' dbo' ) )
62
- exec (' create procedure dbo.cstore_GetAlignment as select 1' );
63
- GO
64
-
65
61
/*
66
62
CSIL - Columnstore Indexes Scripts Library for SQL Server 2016:
67
63
Columnstore Alignment - Shows the alignment (ordering) between the different Columnstore Segments
68
- Version: 1.4.1, November 2016
64
+ Version: 1.4.2, December 2016
69
65
*/
70
- alter procedure dbo .cstore_GetAlignment (
66
+ CREATE OR ALTER PROCEDURE dbo .cstore_GetAlignment (
71
67
-- Params --
72
68
@schemaName nvarchar (256 ) = NULL , -- Allows to show data filtered down to the specified schema
73
69
@tableName nvarchar (256 ) = NULL , -- Allows to show data filtered down to 1 particular table
235
231
/*
236
232
Columnstore Indexes Scripts Library for Azure SQLDatabase:
237
233
Dictionaries Analysis - Shows detailed information about the Columnstore Dictionaries
238
- Version: 1.4.1, November 2016
234
+ Version: 1.4.2, December 2016
239
235
240
236
Copyright 2015-2016 Niko Neugebauer, OH22 IS (http://www.nikoport.com/columnstore/), (http://www.oh22.is/)
241
237
@@ -301,16 +297,12 @@ begin
301
297
end
302
298
303
299
-- ------------------------------------------------------------------------------------------------------------------
304
- if NOT EXISTS (select * from sys .objects where type = ' p' and name = ' cstore_GetDictionaries' and schema_id = SCHEMA_ID (' dbo' ) )
305
- exec (' create procedure dbo.cstore_GetDictionaries as select 1' );
306
- GO
307
-
308
300
/*
309
301
Columnstore Indexes Scripts Library for Azure SQLDatabase:
310
302
Dictionaries Analysis - Shows detailed information about the Columnstore Dictionaries
311
- Version: 1.4.1, November 2016
303
+ Version: 1.4.2, December 2016
312
304
*/
313
- alter procedure dbo .cstore_GetDictionaries (
305
+ CREATE OR ALTER PROCEDURE dbo .cstore_GetDictionaries (
314
306
-- Params --
315
307
@showDetails bit = 1 , -- Enables showing the details of all Dictionaries
316
308
@showWarningsOnly bit = 0 , -- Enables to filter out the dictionaries based on the Dictionary Size (@warningDictionarySizeInMB) and Entry Count (@warningEntryCount)
497
489
/*
498
490
Columnstore Indexes Scripts Library for Azure SQLDatabase:
499
491
Columnstore Fragmenttion - Shows the different types of Columnstore Indexes Fragmentation
500
- Version: 1.4.1, November 2016
492
+ Version: 1.4.2, December 2016
501
493
502
494
Copyright 2015-2016 Niko Neugebauer, OH22 IS (http://www.nikoport.com/columnstore/), (http://www.oh22.is/)
503
495
@@ -558,17 +550,12 @@ begin
558
550
end
559
551
560
552
-- ------------------------------------------------------------------------------------------------------------------
561
-
562
- if NOT EXISTS (select * from sys .objects where type = ' p' and name = ' cstore_GetFragmentation' and schema_id = SCHEMA_ID (' dbo' ) )
563
- exec (' create procedure dbo.cstore_GetFragmentation as select 1' );
564
- GO
565
-
566
553
/*
567
554
Columnstore Indexes Scripts Library for Azure SQLDatabase:
568
555
Columnstore Fragmenttion - Shows the different types of Columnstore Indexes Fragmentation
569
- Version: 1.4.1, November 2016
556
+ Version: 1.4.2, December 2016
570
557
*/
571
- alter procedure dbo .cstore_GetFragmentation (
558
+ CREATE OR ALTER PROCEDURE dbo .cstore_GetFragmentation (
572
559
-- Params --
573
560
@tableName nvarchar (256 ) = NULL , -- Allows to show data filtered down to 1 particular table
574
561
@schemaName nvarchar (256 ) = NULL , -- Allows to show data filtered down to the specified schema
646
633
/*
647
634
Columnstore Indexes Scripts Library for Azure SQLDatabase:
648
635
Row Groups - Shows detailed information on the Columnstore Row Groups inside current Database
649
- Version: 1.4.1, November 2016
636
+ Version: 1.4.2, December 2016
650
637
651
638
Copyright 2015-2016 Niko Neugebauer, OH22 IS (http://www.nikoport.com/columnstore/), (http://www.oh22.is/)
652
639
@@ -690,6 +677,9 @@ Changes in 1.3.0
690
677
Changes in 1.4.0
691
678
- Added support for the Indexed Views with Nonclustered Columnstore Indexes
692
679
- Added new parameter for filtering the Columnstore Object Type with possible values 'Table' & 'Indexed View'
680
+
681
+ Changes in 1.4.2
682
+ - Fixed bug on lookup for the Object Name for the empty Columnstore tables
693
683
*/
694
684
695
685
declare @SQLServerVersion nvarchar (128 ) = cast (SERVERPROPERTY (' ProductVersion' ) as NVARCHAR (128 )),
@@ -704,16 +694,12 @@ begin
704
694
end
705
695
706
696
-- ------------------------------------------------------------------------------------------------------------------
707
- if NOT EXISTS (select * from sys .objects where type = ' p' and name = ' cstore_GetRowGroups' and schema_id = SCHEMA_ID (' dbo' ) )
708
- exec (' create procedure dbo.cstore_GetRowGroups as select 1' );
709
- GO
710
-
711
697
/*
712
698
Columnstore Indexes Scripts Library for Azure SQLDatabase:
713
699
Row Groups - Shows detailed information on the Columnstore Row Groups inside current Database
714
- Version: 1.4.1, November 2016
700
+ Version: 1.4.2, December 2016
715
701
*/
716
- alter procedure dbo .cstore_GetRowGroups (
702
+ CREATE OR ALTER PROCEDURE dbo .cstore_GetRowGroups (
717
703
-- Params --
718
704
@indexType char (2 ) = NULL , -- Allows to filter Columnstore Indexes by their type, with possible values (CC for 'Clustered', NC for 'Nonclustered' or NULL for both)
719
705
@objectType varchar (20 ) = NULL , -- Allows to filter the object type with 2 possible supported values: 'Table' & 'Indexed View'
@@ -743,7 +729,7 @@ begin
743
729
sum (case state when 2 then 1 else 0 end ) as ' Closed DS' ,
744
730
sum (case state when 4 then 1 else 0 end ) as ' Tombstones' ,
745
731
sum (case state when 3 then 1 else 0 end ) as ' Compressed' ,
746
- count (* ) as ' Total' ,
732
+ count (rg . object_id ) as ' Total' ,
747
733
cast ( (sum (isnull (case state when 4 then 0 else deleted_rows end ,0 )) +
748
734
(select isnull (sum (intpart .rows ),0 )
749
735
from sys .internal_partitions intpart
@@ -779,8 +765,8 @@ begin
779
765
and ind .data_space_id = isnull ( case @indexLocation when ' In-Memory' then 0 when ' Disk-Based' then 1 else ind .data_space_id end , ind .data_space_id )
780
766
and case @indexType when ' CC' then 5 when ' NC' then 6 else ind .type end = ind .type
781
767
and case @compressionType when ' Columnstore' then 3 when ' Archive' then 4 else part .data_compression end = part .data_compression
782
- and (@tableName is null or object_name (rg .object_id ) like ' %' + @tableName + ' %' )
783
- and (@schemaName is null or object_schema_name (rg .object_id ) = @schemaName)
768
+ and (@tableName is null or object_name (ind .object_id ) like ' %' + @tableName + ' %' )
769
+ and (@schemaName is null or object_schema_name (ind .object_id ) = @schemaName)
784
770
and obj .type_desc = ISNULL (case @objectType when ' Table' then ' USER_TABLE' when ' Indexed View' then ' VIEW' end ,obj .type_desc )
785
771
group by ind .object_id , ind .type , obj .type_desc , rg .partition_number , ind .data_space_id ,
786
772
part .partition_number
@@ -803,7 +789,7 @@ begin
803
789
sum (case state when 2 then 1 else 0 end ) as ' Closed DS' ,
804
790
sum (case state when 4 then 1 else 0 end ) as ' Tombstones' ,
805
791
sum (case state when 3 then 1 else 0 end ) as ' Compressed' ,
806
- count (* ) as ' Total' ,
792
+ count (rg . object_id ) as ' Total' ,
807
793
cast ( (sum (isnull (case state when 4 then 0 else deleted_rows end ,0 )) +
808
794
(select isnull (sum (intpart .rows ),0 )
809
795
from tempdb .sys .internal_partitions intpart
@@ -839,7 +825,7 @@ begin
839
825
and case @indexType when ' CC' then 5 when ' NC' then 6 else ind .type end = ind .type
840
826
and ind .data_space_id = isnull ( case @indexLocation when ' In-Memory' then 0 when ' Disk-Based' then 1 else ind .data_space_id end , ind .data_space_id )
841
827
and case @compressionType when ' Columnstore' then 3 when ' Archive' then 4 else part .data_compression end = part .data_compression
842
- and (@tableName is null or obj .name like ' %' + @tableName + ' %' )
828
+ and (@tableName is null or ind .name like ' %' + @tableName + ' %' )
843
829
and (@schemaName is null or object_schema_name (ind .object_id , db_id (' tempdb' )) = @schemaName)
844
830
-- and isnull(stat.database_id,db_id('tempdb')) = db_id('tempdb')
845
831
and obj .type_desc = ISNULL (case @objectType when ' Table' then ' USER_TABLE' when ' Indexed View' then ' VIEW' end ,obj .type_desc )
873
859
/*
874
860
Columnstore Indexes Scripts Library for Azure SQLDatabase:
875
861
Row Groups Details - Shows detailed information on the Columnstore Row Groups
876
- Version: 1.4.1, November 2016
862
+ Version: 1.4.2, December 2016
877
863
878
864
Copyright 2015-2016 Niko Neugebauer, OH22 IS (http://www.nikoport.com/columnstore/), (http://www.oh22.is/)
879
865
928
914
/*
929
915
Columnstore Indexes Scripts Library for Azure SQLDatabase:
930
916
Row Groups Details - Shows detailed information on the Columnstore Row Groups
931
- Version: 1.4.1, November 2016
917
+ Version: 1.4.2, December 2016
932
918
*/
933
- alter procedure dbo .cstore_GetRowGroupsDetails (
919
+ CREATE OR ALTER PROCEDURE dbo .cstore_GetRowGroupsDetails (
934
920
-- Params --
935
921
@objectId int = NULL , -- Allows to idenitfy a table thorugh the ObjectId
936
922
@schemaName nvarchar (256 ) = NULL , -- Allows to show data filtered down to the specified schema
1035
1021
/*
1036
1022
Columnstore Indexes Scripts Library for Azure SQL Database:
1037
1023
Suggested Tables - Lists tables which potentially can be interesting for implementing Columnstore Indexes
1038
- Version: 1.4.1, November 2016
1024
+ Version: 1.4.2, December 2016
1039
1025
1040
1026
Copyright 2015-2016 Niko Neugebauer, OH22 IS (http://www.nikoport.com/columnstore/), (http://www.oh22.is/)
1041
1027
@@ -1085,6 +1071,10 @@ Changes in 1.3.1
1085
1071
1086
1072
Changes in 1.4.1
1087
1073
+ Suggestion capability improvements
1074
+
1075
+ Changes in 1.4.2
1076
+ - Fixed bug on the size of the @minSizeToConsiderInGB parameter
1077
+ + Small Improvements for the @columnstoreIndexTypeForTSQL parameter with better quality generation for the complex objects with Primary Keys
1088
1078
*/
1089
1079
1090
1080
declare @SQLServerVersion nvarchar (128 ) = cast (SERVERPROPERTY (' ProductVersion' ) as NVARCHAR (128 )),
@@ -1099,16 +1089,12 @@ begin
1099
1089
end
1100
1090
1101
1091
-- ------------------------------------------------------------------------------------------------------------------
1102
- if NOT EXISTS (select * from sys .objects where type = ' p' and name = ' cstore_SuggestedTables' and schema_id = SCHEMA_ID (' dbo' ) )
1103
- exec (' create procedure dbo.cstore_SuggestedTables as select 1' );
1104
- GO
1105
-
1106
1092
/*
1107
1093
Columnstore Indexes Scripts Library for Azure SQL Database:
1108
1094
Suggested Tables - Lists tables which potentially can be interesting for implementing Columnstore Indexes
1109
- Version: 1.4.1, November 2016
1095
+ Version: 1.4.2, December 2016
1110
1096
*/
1111
- alter procedure dbo .cstore_SuggestedTables (
1097
+ CREATE OR ALTER PROCEDURE dbo .cstore_SuggestedTables (
1112
1098
-- Params --
1113
1099
@minRowsToConsider bigint = 500000 , -- Minimum number of rows for a table to be considered for the suggestion inclusion
1114
1100
@minSizeToConsiderInGB Decimal (16 ,3 ) = 0 .00 , -- Minimum size in GB for a table to be considered for the suggestion inclusion
@@ -1289,7 +1275,7 @@ begin
1289
1275
OR
1290
1276
@considerColumnsOver8K = 1 )
1291
1277
and
1292
- (sum ( a . total_pages ) + isnull (sum (memory_allocated_for_table_kb), 0 ) / 1024 . / 1024 * 8 .0 / 1024 . / 1024 >= @minSizeToConsiderInGB)
1278
+ (isnull (cast ( sum (memory_allocated_for_table_kb) / 1024 . / 1024 as decimal ( 16 , 3 ) ), 0 ) + cast ( sum ( a . total_pages ) * 8 .0 / 1024 . / 1024 as decimal ( 16 , 3 )) >= @minSizeToConsiderInGB)
1293
1279
union all
1294
1280
select t .object_id as [ObjectId]
1295
1281
, ' Disk-Based'
@@ -1410,7 +1396,8 @@ begin
1410
1396
OR
1411
1397
@considerColumnsOver8K = 1 )
1412
1398
and
1413
- (sum (a .total_pages ) * 8 .0 / 1024 . / 1024 >= @minSizeToConsiderInGB);
1399
+ (cast ( sum (a .total_pages ) * 8 .0 / 1024 . / 1024 as decimal (16 ,3 )) >= @minSizeToConsiderInGB);
1400
+
1414
1401
1415
1402
-- Show the found results
1416
1403
select case when ([Triggers] + [FileStream] + [FileTable] + [Unsupported] - ([LOBs] + [Computed])) > 0 then ' None'
@@ -1554,7 +1541,7 @@ end
1554
1541
/*
1555
1542
CSIL - Columnstore Indexes Scripts Library for Azure SQLDatabase:
1556
1543
Columnstore Maintenance - Maintenance Solution for SQL Server Columnstore Indexes
1557
- Version: 1.4.1, November 2016
1544
+ Version: 1.4.2, December 2016
1558
1545
1559
1546
Copyright 2015-2016 Niko Neugebauer, OH22 IS (http://www.nikoport.com/columnstore/), (http://www.oh22.is/)
1560
1547
@@ -1732,16 +1719,12 @@ end
1732
1719
GO
1733
1720
1734
1721
-- **************************************************************************************************************************
1735
- IF NOT EXISTS (select * from sys .objects where type = ' p' and name = ' cstore_doMaintenance' and schema_id = SCHEMA_ID (' dbo' ) )
1736
- exec (' create procedure dbo.cstore_doMaintenance as select 1' );
1737
- GO
1738
-
1739
1722
/*
1740
1723
CSIL - Columnstore Indexes Scripts Library for Azure SQLDatabase:
1741
1724
Columnstore Maintenance - Maintenance Solution for SQL Server Columnstore Indexes
1742
- Version: 1.4.1, November 2016
1725
+ Version: 1.4.2, December 2016
1743
1726
*/
1744
- alter procedure [dbo].[cstore_doMaintenance](
1727
+ CREATE OR ALTER PROCEDURE [dbo].[cstore_doMaintenance](
1745
1728
-- Params --
1746
1729
@execute bit = 0 , -- Controls if the maintenace is executed or not
1747
1730
@orderSegments bit = 0 , -- Controls whether Segment Clustering is being applied or not
0 commit comments