@@ -42,20 +42,24 @@ public static List<Database> GetDatabases(SqlConnection connection) {
4242 }
4343
4444 public static List < DiskInfo > GetDiskInfo ( SqlConnection connection ) {
45- SqlCommand cmd = new SqlCommand ( Query . DiskInfo , connection ) { CommandTimeout = Settings . Options . CommandTimeout } ;
45+ List < DiskInfo > di = new List < DiskInfo > ( ) ;
4646
47- SqlDataAdapter adapter = new SqlDataAdapter ( cmd ) ;
48- DataSet data = new DataSet ( ) ;
49- adapter . Fill ( data ) ;
47+ if ( ! Settings . ServerInfo . IsAzure && Settings . ServerInfo . IsSysAdmin ) {
48+ SqlCommand cmd = new SqlCommand ( Query . DiskInfo , connection ) { CommandTimeout = Settings . Options . CommandTimeout } ;
5049
51- List < DiskInfo > di = new List < DiskInfo > ( ) ;
52- foreach ( DataRow _ in data . Tables [ 0 ] . Rows ) {
53- di . Add (
54- new DiskInfo {
55- Drive = _ . Field < string > ( 0 ) ,
56- FreeSpace = _ . Field < int > ( 1 )
57- }
58- ) ;
50+ SqlDataAdapter adapter = new SqlDataAdapter ( cmd ) ;
51+ DataSet data = new DataSet ( ) ;
52+ adapter . Fill ( data ) ;
53+
54+
55+ foreach ( DataRow _ in data . Tables [ 0 ] . Rows ) {
56+ di . Add (
57+ new DiskInfo {
58+ Drive = _ . Field < string > ( 0 ) ,
59+ FreeSpace = _ . Field < int > ( 1 )
60+ }
61+ ) ;
62+ }
5963 }
6064
6165 return di ;
@@ -135,24 +139,27 @@ public static List<Index> GetIndexes(SqlConnection connection) {
135139 if ( ! string . IsNullOrEmpty ( includeListObject ) )
136140 includeListObject = $ "AND ( 1 = 0 { includeListObject } )";
137141
142+ int filterRows = Settings . Options . ShowOnlyMore1000Rows ? 1000 : 0 ;
143+
138144 string includeList = string . IsNullOrEmpty ( includeListSchemas ) && string . IsNullOrEmpty ( includeListObject )
139- ? Query . IncludeListEmpty
140- : string . Format ( Query . IncludeList , includeListSchemas , includeListObject ) ;
145+ ? string . Format ( Query . IncludeListEmpty , filterRows )
146+ : string . Format ( Query . IncludeList , filterRows , includeListSchemas , includeListObject ) ;
141147
142- string ignoreReadOnlyFL = Settings . Options . IgnoreReadOnlyFL ? "" : "AND fg.[is_read_only] = 0" ;
143- string ignorePermissions = Settings . Options . IgnorePermissions ? "" : "AND PERMISSIONS(i.[object_id]) & 2 = 2" ;
148+ string ignoreReadOnlyFL = Settings . Options . IgnoreReadOnlyFL ? "" : "AND fg.[is_read_only] = 0 " ;
149+ string ignorePermissions = Settings . Options . IgnorePermissions ? "" : "AND PERMISSIONS(i.[object_id]) & 2 = 2 " ;
150+ string ignoreHeapWithCompression = Settings . Options . IgnoreHeapWithCompression ? "AND (i.[type] != 0 OR (i.[type] = 0 AND p.DataCompression = 0)) " : "" ;
144151
145152 string query = string . Format ( Query . PreDescribeIndexes ,
146153 string . Join ( ", " , it ) , excludeList , indexQuery , lob ,
147- indexStats , ignoreReadOnlyFL , ignorePermissions , includeList ) ;
154+ indexStats , ignoreReadOnlyFL , ignorePermissions , includeList , ignoreHeapWithCompression ) ;
148155
149156 SqlCommand cmd = new SqlCommand ( query , connection ) { CommandTimeout = Settings . Options . CommandTimeout } ;
150157
151- cmd . Parameters . Add ( new SqlParameter ( "@Fragmentation" , SqlDbType . Float ) { Value = threshold } ) ;
152- cmd . Parameters . Add ( new SqlParameter ( "@MinIndexSize" , SqlDbType . BigInt ) { Value = Settings . Options . MinIndexSize . PageSize ( ) } ) ;
153- cmd . Parameters . Add ( new SqlParameter ( "@MaxIndexSize" , SqlDbType . BigInt ) { Value = Settings . Options . MaxIndexSize . PageSize ( ) } ) ;
154- cmd . Parameters . Add ( new SqlParameter ( "@PreDescribeSize" , SqlDbType . BigInt ) { Value = Settings . Options . PreDescribeSize . PageSize ( ) } ) ;
155- cmd . Parameters . Add ( new SqlParameter ( "@ScanMode" , SqlDbType . NVarChar , 100 ) { Value = Settings . Options . ScanMode } ) ;
158+ cmd . Parameters . Add ( new SqlParameter ( "@Fragmentation" , SqlDbType . Float ) { Value = threshold } ) ;
159+ cmd . Parameters . Add ( new SqlParameter ( "@MinIndexSize" , SqlDbType . BigInt ) { Value = Settings . Options . MinIndexSize . PageSize ( ) } ) ;
160+ cmd . Parameters . Add ( new SqlParameter ( "@MaxIndexSize" , SqlDbType . BigInt ) { Value = Settings . Options . MaxIndexSize . PageSize ( ) } ) ;
161+ cmd . Parameters . Add ( new SqlParameter ( "@PreDescribeSize" , SqlDbType . BigInt ) { Value = Settings . Options . PreDescribeSize . PageSize ( ) } ) ;
162+ cmd . Parameters . Add ( new SqlParameter ( "@ScanMode" , SqlDbType . NVarChar , 100 ) { Value = Settings . Options . ScanMode } ) ;
156163
157164 SqlDataAdapter adapter = new SqlDataAdapter ( cmd ) ;
158165 DataSet data = new DataSet ( ) ;
@@ -330,8 +337,10 @@ public static void GetColumnstoreFragmentation(SqlConnection connection, Index i
330337 }
331338
332339 public static string FixIndex ( SqlConnection connection , Index ix ) {
340+ int indexId = ix . FixType == IndexOp . CREATE_COLUMNSTORE_INDEX && ix . IndexType == IndexType . HEAP ? 1 : ix . IndexId ;
341+
333342 string sqlInfo = string . Format ( ix . IsColumnstore ? Query . AfterFixColumnstoreIndex : Query . AfterFixIndex ,
334- ix . ObjectId , ix . IndexId , ix . PartitionNumber , Settings . Options . ScanMode ) ;
343+ ix . ObjectId , indexId , ix . PartitionNumber , Settings . Options . ScanMode ) ;
335344
336345 string query = ix . GetQuery ( ) ;
337346 string sql = ix . FixType == IndexOp . DISABLE_INDEX
@@ -356,7 +365,6 @@ public static string FixIndex(SqlConnection connection, Index ix) {
356365 }
357366
358367 if ( string . IsNullOrEmpty ( ix . Error ) ) {
359-
360368 try {
361369 if ( ix . FixType == IndexOp . UPDATE_STATISTICS_FULL || ix . FixType == IndexOp . UPDATE_STATISTICS_RESAMPLE || ix . FixType == IndexOp . UPDATE_STATISTICS_SAMPLE ) {
362370 ix . IndexStats = DateTime . Now ;
@@ -383,6 +391,11 @@ public static string FixIndex(SqlConnection connection, Index ix) {
383391 ix . RowsCount = row . Field < long > ( Resources . RowsCount ) ;
384392 ix . DataCompression = ( ( DataCompression ) row . Field < byte > ( Resources . DataCompression ) ) ;
385393 ix . IndexStats = row . Field < DateTime ? > ( Resources . IndexStats ) ;
394+
395+ if ( ix . FixType == IndexOp . CREATE_COLUMNSTORE_INDEX ) {
396+ ix . IndexName = "CCL" ;
397+ ix . IndexType = IndexType . CLUSTERED_COLUMNSTORE ;
398+ }
386399 }
387400 }
388401 catch ( Exception ex ) {
@@ -447,10 +460,10 @@ private static IndexOp CorrectIndexOp(IndexOp op, Index ix) {
447460 if ( Settings . Options . DataCompression == DataCompression . NONE && ix . DataCompression != DataCompression . NONE )
448461 return IndexOp . REBUILD_NONE ;
449462
450- if ( Settings . Options . DataCompression == DataCompression . ROW )
463+ if ( Settings . Options . DataCompression == DataCompression . ROW && ix . DataCompression != DataCompression . ROW )
451464 return IndexOp . REBUILD_ROW ;
452465
453- if ( Settings . Options . DataCompression == DataCompression . PAGE )
466+ if ( Settings . Options . DataCompression == DataCompression . PAGE && ix . DataCompression != DataCompression . PAGE )
454467 return IndexOp . REBUILD_PAGE ;
455468 }
456469
0 commit comments