Skip to content

Commit 387dde7

Browse files
author
Sergey Syrovatchenko
committed
Move heaps to CCL indexes, new filter options
1 parent 17021a5 commit 387dde7

File tree

12 files changed

+231
-99
lines changed

12 files changed

+231
-99
lines changed

Forms/ActionBox.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ public ActionBox() {
2525
IndexOp.REBUILD_COLUMNSTORE_ARCHIVE
2626
}
2727
);
28+
29+
if (Settings.ServerInfo.MajorVersion >= ServerVersion.Sql2016) {
30+
indexOps.Add(IndexOp.CREATE_COLUMNSTORE_INDEX);
31+
}
2832
}
2933

3034
if (Settings.ServerInfo.IsOnlineRebuildAvailable) {

Forms/MainBox.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,10 @@ private List<IndexOp> GetIndexOperations(Index ix) {
605605
? IndexOp.REBUILD_ROW
606606
: IndexOp.REBUILD_PAGE);
607607
}
608+
609+
if (!ix.IsPartitioned && ix.IndexType == IndexType.HEAP && Settings.ServerInfo.MajorVersion >= ServerVersion.Sql2016) {
610+
i.Add(IndexOp.CREATE_COLUMNSTORE_INDEX);
611+
}
608612
}
609613

610614
if (ix.IsAllowOnlineRebuild)
@@ -691,9 +695,6 @@ private void GridRowCellClick(object sender, RowCellClickEventArgs e) {
691695
}
692696

693697
private void GridPopupMenuShowing(object sender, PopupMenuShowingEventArgs e) {
694-
var col = e.HitInfo.Column;
695-
if (col == null) return;
696-
697698
if (e.MenuType == GridMenuType.Column) {
698699
string[] columns = {
699700
GridLocalizer.Active.GetLocalizedString(GridStringId.MenuColumnGroup),
@@ -704,7 +705,12 @@ private void GridPopupMenuShowing(object sender, PopupMenuShowingEventArgs e) {
704705
if (columns.Contains(item.Caption))
705706
item.Visible = false;
706707
}
708+
}
707709

710+
var col = e.HitInfo.Column;
711+
if (col == null) return;
712+
713+
if (e.MenuType == GridMenuType.Column) {
708714
if (col.Caption == Resources.Selection || col.Caption == Resources.Progress)
709715
return;
710716

Forms/SettingsBox.Designer.cs

Lines changed: 141 additions & 60 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Forms/SettingsBox.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ private void UpdateControls(Options o) {
5151
boxPadIndex.Checked = o.PadIndex;
5252
boxSortInTempDb.Checked = o.SortInTempDb;
5353
boxLobCompaction.Checked = o.LobCompaction;
54+
boxMultiThreadingCount.Value = o.DelayAfterFix;
5455
boxDelayAfterFix.Value = o.DelayAfterFix;
56+
boxMultiThreadingCount.Value = o.MultiThreadingCount;
5557
boxMaxDod.Value = o.MaxDop;
5658
boxStatsSamplePercent.Value = o.SampleStatsPercent;
5759
boxConnectionTimeout.Value = o.ConnectionTimeout;
@@ -78,6 +80,8 @@ private void UpdateControls(Options o) {
7880
boxExcludeObject.EditValue = string.Join(";", o.ExcludeObject);
7981
boxIgnorePermissions.Checked = o.IgnorePermissions;
8082
boxIgnoreReadOnlyFL.Checked = o.IgnoreReadOnlyFL;
83+
boxIgnoreHeapWithCompression.Checked = o.IgnoreHeapWithCompression;
84+
boxShowOnlyMore1000Rows.Checked = o.ShowOnlyMore1000Rows;
8185
}
8286

8387
public Options GetSettings() {
@@ -91,6 +95,7 @@ public Options GetSettings() {
9195
PreDescribeSize = boxMinIndexSize.Value.Maximum,
9296
MaxIndexSize = boxMaxIndexSize.Value,
9397
DelayAfterFix = (int)boxDelayAfterFix.Value,
98+
MultiThreadingCount = (int)boxMultiThreadingCount.Value,
9499
MaxDop = (int)boxMaxDod.Value,
95100
Online = boxOnline.Checked,
96101
PadIndex = boxPadIndex.Checked,
@@ -120,7 +125,9 @@ public Options GetSettings() {
120125
IncludeObject = new List<string> (boxIncludeObject.EditValue.ToString().Split(';')),
121126
ExcludeObject = new List<string> (boxExcludeObject.EditValue.ToString().Split(';')),
122127
IgnorePermissions = boxIgnorePermissions.Checked,
123-
IgnoreReadOnlyFL = boxIgnoreReadOnlyFL.Checked
128+
IgnoreReadOnlyFL = boxIgnoreReadOnlyFL.Checked,
129+
IgnoreHeapWithCompression = boxIgnoreHeapWithCompression.Checked,
130+
ShowOnlyMore1000Rows = boxShowOnlyMore1000Rows.Checked
124131
};
125132

126133
}

Forms/SettingsBox.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,9 @@
156156
<metadata name="groupControl3.GenerateMember" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
157157
<value>False</value>
158158
</metadata>
159+
<metadata name="labelControl1.GenerateMember" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
160+
<value>False</value>
161+
</metadata>
159162
<metadata name="labelControl3.GenerateMember" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
160163
<value>False</value>
161164
</metadata>

Program.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ static void Main(string[] args) {
4141

4242
SplashScreenManager.ShowForm(typeof(SplashScreenBox));
4343
var mainBox = new MainBox();
44-
Thread.Sleep(100);
4544
SplashScreenManager.CloseForm();
4645

4746
Application.Run(mainBox);

Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@
77
[assembly: AssemblyCopyright("Sergii Syrovatchenko")]
88
[assembly: AssemblyTrademark("")]
99
[assembly: AssemblyCulture("")]
10-
[assembly: AssemblyVersion("1.0.0.62")]
11-
[assembly: AssemblyFileVersion("1.0.0.62")]
10+
[assembly: AssemblyVersion("1.0.0.63")]
11+
[assembly: AssemblyFileVersion("1.0.0.63")]

Server/Index.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,10 @@ public string GetQuery() {
6262
string fullIndexName = $"{indexName} ON {objectName}";
6363
string partition = IsPartitioned ? PartitionNumber.ToString() : "ALL";
6464

65-
if (IsColumnstore) {
65+
if (IndexType == IndexType.HEAP && FixType == IndexOp.CREATE_COLUMNSTORE_INDEX) {
66+
sql = $"CREATE CLUSTERED COLUMNSTORE INDEX [CCL] ON {objectName} WITH (COMPRESSION_DELAY = 0, DATA_COMPRESSION = {DataCompression.COLUMNSTORE});";
67+
}
68+
else if (IsColumnstore) {
6669

6770
switch (FixType) {
6871
case IndexOp.REBUILD:

Server/Query.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ GROUP BY p.[object_id]
8181
, p.[index_id]
8282
, p.[partition_number]
8383
) p
84-
JOIN sys.indexes i WITH(NOLOCK) ON i.[object_id] = p.ObjectID AND i.[index_id] = p.IndexID {6}
84+
JOIN sys.indexes i WITH(NOLOCK) ON i.[object_id] = p.ObjectID AND i.[index_id] = p.IndexID {6} {8}
8585
WHERE i.[type] IN ({0})
8686
AND i.[object_id] > 255
8787
AND (
@@ -371,7 +371,7 @@ SELECT [object_id]
371371
INTO #Partitions
372372
FROM sys.partitions WITH(NOLOCK)
373373
WHERE [object_id] > 255
374-
AND [rows] > 0
374+
AND [rows] > {0}
375375
AND [object_id] NOT IN (SELECT * FROM #ExcludeList)";
376376

377377
public const string IncludeList = @"
@@ -384,7 +384,7 @@ INSERT INTO #IncludeList
384384
SELECT [object_id]
385385
FROM sys.objects WITH(NOLOCK)
386386
WHERE [type] IN ('V', 'U')
387-
{0}{1}
387+
{1}{2}
388388
389389
SELECT [object_id]
390390
, [index_id]
@@ -395,7 +395,7 @@ SELECT [object_id]
395395
INTO #Partitions
396396
FROM sys.partitions WITH(NOLOCK)
397397
WHERE [object_id] > 255
398-
AND [rows] > 0
398+
AND [rows] > {0}
399399
AND [object_id] NOT IN (SELECT * FROM #ExcludeList)
400400
AND [object_id] IN (SELECT * FROM #IncludeList)";
401401

Server/QueryEngine.cs

Lines changed: 39 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)