Skip to content

Commit

Permalink
Move heaps to CCL indexes, new filter options
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergey Syrovatchenko committed May 31, 2020
1 parent 17021a5 commit 387dde7
Show file tree
Hide file tree
Showing 12 changed files with 231 additions and 99 deletions.
4 changes: 4 additions & 0 deletions Forms/ActionBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ public partial class ActionBox : XtraForm {
IndexOp.REBUILD_COLUMNSTORE_ARCHIVE
}
);

if (Settings.ServerInfo.MajorVersion >= ServerVersion.Sql2016) {
indexOps.Add(IndexOp.CREATE_COLUMNSTORE_INDEX);
}
}

if (Settings.ServerInfo.IsOnlineRebuildAvailable) {
Expand Down
12 changes: 9 additions & 3 deletions Forms/MainBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,10 @@ public partial class MainBox : RibbonForm {
? IndexOp.REBUILD_ROW
: IndexOp.REBUILD_PAGE);
}

if (!ix.IsPartitioned && ix.IndexType == IndexType.HEAP && Settings.ServerInfo.MajorVersion >= ServerVersion.Sql2016) {
i.Add(IndexOp.CREATE_COLUMNSTORE_INDEX);
}
}

if (ix.IsAllowOnlineRebuild)
Expand Down Expand Up @@ -691,9 +695,6 @@ public partial class MainBox : RibbonForm {
}

private void GridPopupMenuShowing(object sender, PopupMenuShowingEventArgs e) {
var col = e.HitInfo.Column;
if (col == null) return;

if (e.MenuType == GridMenuType.Column) {
string[] columns = {
GridLocalizer.Active.GetLocalizedString(GridStringId.MenuColumnGroup),
Expand All @@ -704,7 +705,12 @@ public partial class MainBox : RibbonForm {
if (columns.Contains(item.Caption))
item.Visible = false;
}
}

var col = e.HitInfo.Column;
if (col == null) return;

if (e.MenuType == GridMenuType.Column) {
if (col.Caption == Resources.Selection || col.Caption == Resources.Progress)
return;

Expand Down
201 changes: 141 additions & 60 deletions Forms/SettingsBox.Designer.cs

Large diffs are not rendered by default.

9 changes: 8 additions & 1 deletion Forms/SettingsBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ public partial class SettingsBox : XtraForm {
boxPadIndex.Checked = o.PadIndex;
boxSortInTempDb.Checked = o.SortInTempDb;
boxLobCompaction.Checked = o.LobCompaction;
boxMultiThreadingCount.Value = o.DelayAfterFix;
boxDelayAfterFix.Value = o.DelayAfterFix;
boxMultiThreadingCount.Value = o.MultiThreadingCount;
boxMaxDod.Value = o.MaxDop;
boxStatsSamplePercent.Value = o.SampleStatsPercent;
boxConnectionTimeout.Value = o.ConnectionTimeout;
Expand All @@ -78,6 +80,8 @@ public partial class SettingsBox : XtraForm {
boxExcludeObject.EditValue = string.Join(";", o.ExcludeObject);
boxIgnorePermissions.Checked = o.IgnorePermissions;
boxIgnoreReadOnlyFL.Checked = o.IgnoreReadOnlyFL;
boxIgnoreHeapWithCompression.Checked = o.IgnoreHeapWithCompression;
boxShowOnlyMore1000Rows.Checked = o.ShowOnlyMore1000Rows;
}

public Options GetSettings() {
Expand All @@ -91,6 +95,7 @@ public partial class SettingsBox : XtraForm {
PreDescribeSize = boxMinIndexSize.Value.Maximum,
MaxIndexSize = boxMaxIndexSize.Value,
DelayAfterFix = (int)boxDelayAfterFix.Value,
MultiThreadingCount = (int)boxMultiThreadingCount.Value,
MaxDop = (int)boxMaxDod.Value,
Online = boxOnline.Checked,
PadIndex = boxPadIndex.Checked,
Expand Down Expand Up @@ -120,7 +125,9 @@ public partial class SettingsBox : XtraForm {
IncludeObject = new List<string> (boxIncludeObject.EditValue.ToString().Split(';')),
ExcludeObject = new List<string> (boxExcludeObject.EditValue.ToString().Split(';')),
IgnorePermissions = boxIgnorePermissions.Checked,
IgnoreReadOnlyFL = boxIgnoreReadOnlyFL.Checked
IgnoreReadOnlyFL = boxIgnoreReadOnlyFL.Checked,
IgnoreHeapWithCompression = boxIgnoreHeapWithCompression.Checked,
ShowOnlyMore1000Rows = boxShowOnlyMore1000Rows.Checked
};

}
Expand Down
3 changes: 3 additions & 0 deletions Forms/SettingsBox.resx
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,9 @@
<metadata name="groupControl3.GenerateMember" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>False</value>
</metadata>
<metadata name="labelControl1.GenerateMember" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>False</value>
</metadata>
<metadata name="labelControl3.GenerateMember" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>False</value>
</metadata>
Expand Down
1 change: 0 additions & 1 deletion Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ static class Program {

SplashScreenManager.ShowForm(typeof(SplashScreenBox));
var mainBox = new MainBox();
Thread.Sleep(100);
SplashScreenManager.CloseForm();

Application.Run(mainBox);
Expand Down
4 changes: 2 additions & 2 deletions Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
[assembly: AssemblyCopyright("Sergii Syrovatchenko")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: AssemblyVersion("1.0.0.62")]
[assembly: AssemblyFileVersion("1.0.0.62")]
[assembly: AssemblyVersion("1.0.0.63")]
[assembly: AssemblyFileVersion("1.0.0.63")]
5 changes: 4 additions & 1 deletion Server/Index.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,10 @@ public class Index {
string fullIndexName = $"{indexName} ON {objectName}";
string partition = IsPartitioned ? PartitionNumber.ToString() : "ALL";

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

switch (FixType) {
case IndexOp.REBUILD:
Expand Down
8 changes: 4 additions & 4 deletions Server/Query.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ SELECT p.ObjectID
, p.[index_id]
, p.[partition_number]
) p
JOIN sys.indexes i WITH(NOLOCK) ON i.[object_id] = p.ObjectID AND i.[index_id] = p.IndexID {6}
JOIN sys.indexes i WITH(NOLOCK) ON i.[object_id] = p.ObjectID AND i.[index_id] = p.IndexID {6} {8}
WHERE i.[type] IN ({0})
AND i.[object_id] > 255
AND (
Expand Down Expand Up @@ -371,7 +371,7 @@ SELECT i.ObjectID
INTO #Partitions
FROM sys.partitions WITH(NOLOCK)
WHERE [object_id] > 255
AND [rows] > 0
AND [rows] > {0}
AND [object_id] NOT IN (SELECT * FROM #ExcludeList)";

public const string IncludeList = @"
Expand All @@ -384,7 +384,7 @@ SELECT i.ObjectID
SELECT [object_id]
FROM sys.objects WITH(NOLOCK)
WHERE [type] IN ('V', 'U')
{0}{1}
{1}{2}
SELECT [object_id]
, [index_id]
Expand All @@ -395,7 +395,7 @@ SELECT i.ObjectID
INTO #Partitions
FROM sys.partitions WITH(NOLOCK)
WHERE [object_id] > 255
AND [rows] > 0
AND [rows] > {0}
AND [object_id] NOT IN (SELECT * FROM #ExcludeList)
AND [object_id] IN (SELECT * FROM #IncludeList)";

Expand Down
65 changes: 39 additions & 26 deletions Server/QueryEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,24 @@ public static class QueryEngine {
}

public static List<DiskInfo> GetDiskInfo(SqlConnection connection) {
SqlCommand cmd = new SqlCommand(Query.DiskInfo, connection) { CommandTimeout = Settings.Options.CommandTimeout };
List<DiskInfo> di = new List<DiskInfo>();

SqlDataAdapter adapter = new SqlDataAdapter(cmd);
DataSet data = new DataSet();
adapter.Fill(data);
if (!Settings.ServerInfo.IsAzure && Settings.ServerInfo.IsSysAdmin) {
SqlCommand cmd = new SqlCommand(Query.DiskInfo, connection) { CommandTimeout = Settings.Options.CommandTimeout };

List<DiskInfo> di = new List<DiskInfo>();
foreach (DataRow _ in data.Tables[0].Rows) {
di.Add(
new DiskInfo {
Drive = _.Field<string>(0),
FreeSpace = _.Field<int>(1)
}
);
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
DataSet data = new DataSet();
adapter.Fill(data);


foreach (DataRow _ in data.Tables[0].Rows) {
di.Add(
new DiskInfo {
Drive = _.Field<string>(0),
FreeSpace = _.Field<int>(1)
}
);
}
}

return di;
Expand Down Expand Up @@ -135,24 +139,27 @@ public static class QueryEngine {
if (!string.IsNullOrEmpty(includeListObject))
includeListObject = $"AND ( 1 = 0 {includeListObject})";

int filterRows = Settings.Options.ShowOnlyMore1000Rows ? 1000 : 0;

string includeList = string.IsNullOrEmpty(includeListSchemas) && string.IsNullOrEmpty(includeListObject)
? Query.IncludeListEmpty
: string.Format(Query.IncludeList, includeListSchemas, includeListObject);
? string.Format(Query.IncludeListEmpty, filterRows)
: string.Format(Query.IncludeList, filterRows, includeListSchemas, includeListObject);

string ignoreReadOnlyFL = Settings.Options.IgnoreReadOnlyFL ? "" : "AND fg.[is_read_only] = 0";
string ignorePermissions = Settings.Options.IgnorePermissions ? "" : "AND PERMISSIONS(i.[object_id]) & 2 = 2";
string ignoreReadOnlyFL = Settings.Options.IgnoreReadOnlyFL ? "" : "AND fg.[is_read_only] = 0 ";
string ignorePermissions = Settings.Options.IgnorePermissions ? "" : "AND PERMISSIONS(i.[object_id]) & 2 = 2 ";
string ignoreHeapWithCompression = Settings.Options.IgnoreHeapWithCompression ? "AND (i.[type] != 0 OR (i.[type] = 0 AND p.DataCompression = 0)) " : "";

string query = string.Format(Query.PreDescribeIndexes,
string.Join(", ", it), excludeList, indexQuery, lob,
indexStats, ignoreReadOnlyFL, ignorePermissions, includeList);
indexStats, ignoreReadOnlyFL, ignorePermissions, includeList, ignoreHeapWithCompression);

SqlCommand cmd = new SqlCommand(query, connection) { CommandTimeout = Settings.Options.CommandTimeout };

cmd.Parameters.Add(new SqlParameter("@Fragmentation", SqlDbType.Float) { Value = threshold });
cmd.Parameters.Add(new SqlParameter("@MinIndexSize", SqlDbType.BigInt) { Value = Settings.Options.MinIndexSize.PageSize() });
cmd.Parameters.Add(new SqlParameter("@MaxIndexSize", SqlDbType.BigInt) { Value = Settings.Options.MaxIndexSize.PageSize() });
cmd.Parameters.Add(new SqlParameter("@PreDescribeSize", SqlDbType.BigInt) { Value = Settings.Options.PreDescribeSize.PageSize() });
cmd.Parameters.Add(new SqlParameter("@ScanMode", SqlDbType.NVarChar, 100) { Value = Settings.Options.ScanMode });
cmd.Parameters.Add(new SqlParameter("@Fragmentation", SqlDbType.Float) { Value = threshold });
cmd.Parameters.Add(new SqlParameter("@MinIndexSize", SqlDbType.BigInt) { Value = Settings.Options.MinIndexSize.PageSize() });
cmd.Parameters.Add(new SqlParameter("@MaxIndexSize", SqlDbType.BigInt) { Value = Settings.Options.MaxIndexSize.PageSize() });
cmd.Parameters.Add(new SqlParameter("@PreDescribeSize", SqlDbType.BigInt) { Value = Settings.Options.PreDescribeSize.PageSize() });
cmd.Parameters.Add(new SqlParameter("@ScanMode", SqlDbType.NVarChar, 100) { Value = Settings.Options.ScanMode });

SqlDataAdapter adapter = new SqlDataAdapter(cmd);
DataSet data = new DataSet();
Expand Down Expand Up @@ -330,8 +337,10 @@ public static class QueryEngine {
}

public static string FixIndex(SqlConnection connection, Index ix) {
int indexId = ix.FixType == IndexOp.CREATE_COLUMNSTORE_INDEX && ix.IndexType == IndexType.HEAP ? 1 : ix.IndexId;

string sqlInfo = string.Format(ix.IsColumnstore ? Query.AfterFixColumnstoreIndex : Query.AfterFixIndex,
ix.ObjectId, ix.IndexId, ix.PartitionNumber, Settings.Options.ScanMode);
ix.ObjectId, indexId, ix.PartitionNumber, Settings.Options.ScanMode);

string query = ix.GetQuery();
string sql = ix.FixType == IndexOp.DISABLE_INDEX
Expand All @@ -356,7 +365,6 @@ public static class QueryEngine {
}

if (string.IsNullOrEmpty(ix.Error)) {

try {
if (ix.FixType == IndexOp.UPDATE_STATISTICS_FULL || ix.FixType == IndexOp.UPDATE_STATISTICS_RESAMPLE || ix.FixType == IndexOp.UPDATE_STATISTICS_SAMPLE) {
ix.IndexStats = DateTime.Now;
Expand All @@ -383,6 +391,11 @@ public static class QueryEngine {
ix.RowsCount = row.Field<long>(Resources.RowsCount);
ix.DataCompression = ((DataCompression)row.Field<byte>(Resources.DataCompression));
ix.IndexStats = row.Field<DateTime?>(Resources.IndexStats);

if (ix.FixType == IndexOp.CREATE_COLUMNSTORE_INDEX) {
ix.IndexName = "CCL";
ix.IndexType = IndexType.CLUSTERED_COLUMNSTORE;
}
}
}
catch (Exception ex) {
Expand Down Expand Up @@ -447,10 +460,10 @@ public static class QueryEngine {
if (Settings.Options.DataCompression == DataCompression.NONE && ix.DataCompression != DataCompression.NONE)
return IndexOp.REBUILD_NONE;

if (Settings.Options.DataCompression == DataCompression.ROW)
if (Settings.Options.DataCompression == DataCompression.ROW && ix.DataCompression != DataCompression.ROW)
return IndexOp.REBUILD_ROW;

if (Settings.Options.DataCompression == DataCompression.PAGE)
if (Settings.Options.DataCompression == DataCompression.PAGE && ix.DataCompression != DataCompression.PAGE)
return IndexOp.REBUILD_PAGE;
}

Expand Down
13 changes: 13 additions & 0 deletions Settings/Options.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class Options {
private int _connectionTimeout = 15;
private int _commandTimeout = 120;
private int _delayAfterFix;
private int _multiThreadingCount = 1;
private int _maxDop;
private int _fillFactor;
private int _sampleStatsPercent = 100;
Expand Down Expand Up @@ -94,6 +95,12 @@ public class Options {
set => _delayAfterFix = value.IsBetween(0, 5000) ? value : _delayAfterFix;
}

[XmlAttribute]
public int MultiThreadingCount {
get => _multiThreadingCount;
set => _multiThreadingCount = value.IsBetween(1, 1) ? value : _multiThreadingCount;
}

[XmlAttribute]
public int MaxDop {
get => _maxDop;
Expand Down Expand Up @@ -172,6 +179,12 @@ public class Options {
[XmlAttribute]
public bool IgnoreReadOnlyFL;

[XmlAttribute]
public bool IgnoreHeapWithCompression;

[XmlAttribute]
public bool ShowOnlyMore1000Rows;

[XmlElement]
public List<string> IncludeSchemas {
get => _includeSchemas;
Expand Down
5 changes: 4 additions & 1 deletion Types/IndexOp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@ public enum IndexOp {
IGNORE = 17,

[Description("SKIP")]
SKIP = 18
SKIP = 18,

[Description("CREATE COLUMNSTORE INDEX")]
CREATE_COLUMNSTORE_INDEX = 19
}

}

0 comments on commit 387dde7

Please sign in to comment.