forked from sergiisyrovatchenko/SQLIndexManager
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOptions.cs
More file actions
229 lines (187 loc) · 6.26 KB
/
Copy pathOptions.cs
File metadata and controls
229 lines (187 loc) · 6.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
using System;
using System.Collections.Generic;
using System.Xml.Serialization;
namespace SQLIndexManager {
[Serializable]
public class Options {
public const string DEFAULT = "DEFAULT";
public const string NONE = "NONE";
public const string ON = "ON";
public const string OFF = "OFF";
public const string LIMITED = "LIMITED";
private int _reorganizeThreshold = 15;
private int _rebuildThreshold = 30;
private int _minIndexSize = 6;
private int _preDescribeSize = 256;
private int _maxIndexSize = 8192;
private int _connectionTimeout = 15;
private int _commandTimeout = 120;
private int _maxDop;
private int _fillFactor;
private int _sampleStatsPercent = 100;
private int _maxDuration = 1;
private string _abortAfterWait = NONE;
private string _dataCompression = DEFAULT;
private string _noRecompute = DEFAULT;
private string _scanMode = LIMITED;
private List<string> _includeSchemas = new List<string>();
private List<string> _excludeSchemas = new List<string>();
private List<string> _includeObject = new List<string>();
private List<string> _excludeObject = new List<string>();
[XmlAttribute]
public int ConnectionTimeout {
get => _connectionTimeout;
set => _connectionTimeout = value.IsBetween(15, 90) ? value : _connectionTimeout;
}
[XmlAttribute]
public int CommandTimeout {
get => _commandTimeout;
set => _commandTimeout = value.IsBetween(0, 1800) ? value : _commandTimeout;
}
[XmlAttribute]
public int ReorganizeThreshold {
get => _reorganizeThreshold;
set => UpdateThreshold(value, _rebuildThreshold);
}
[XmlAttribute]
public int RebuildThreshold {
get => _rebuildThreshold;
set => UpdateThreshold(_reorganizeThreshold, value);
}
[XmlAttribute]
public int MaxDop {
get => _maxDop;
set => _maxDop = value.IsBetween(0, 64) ? value : _maxDop;
}
[XmlAttribute]
public int FillFactor {
get => _fillFactor;
set => _fillFactor = value.IsBetween(0, 100) ? value : _fillFactor;
}
[XmlAttribute]
public int SampleStatsPercent {
get => _sampleStatsPercent;
set => _sampleStatsPercent = value.IsBetween(1, 100) ? value : _sampleStatsPercent;
}
[XmlAttribute]
public int MinIndexSize {
get => _minIndexSize;
set => UpdateSize(value, _preDescribeSize, _maxIndexSize);
}
[XmlAttribute]
public int PreDescribeSize {
get => _preDescribeSize;
set => UpdateSize(_minIndexSize, value, _maxIndexSize);
}
[XmlAttribute]
public int MaxIndexSize {
get => _maxIndexSize;
set => UpdateSize(_minIndexSize, _preDescribeSize, value);
}
[XmlAttribute]
public bool Online;
[XmlAttribute]
public bool SortInTempDb;
[XmlAttribute]
public bool LobCompaction;
[XmlAttribute]
public bool WaitAtLowPriority;
[XmlAttribute]
public bool ScanHeap;
[XmlAttribute]
public bool ScanClusteredIndex;
[XmlAttribute]
public bool ScanNonClusteredIndex;
[XmlAttribute]
public bool ScanClusteredColumnstore;
[XmlAttribute]
public bool ScanNonClusteredColumnstore;
[XmlAttribute]
public bool ScanMissingIndex;
[XmlAttribute]
public bool IgnorePermissions;
[XmlAttribute]
public bool IgnoreReadOnlyFL;
[XmlElement]
public List<string> IncludeSchemas {
get => _includeSchemas;
set => _includeSchemas = value.RemoveInvalidTokens();
}
[XmlElement]
public List<string> ExcludeSchemas {
get => _excludeSchemas;
set => _excludeSchemas = value.RemoveInvalidTokens();
}
[XmlElement]
public List<string> ExcludeObject {
get => _excludeObject;
set => _excludeObject = value.RemoveInvalidTokens();
}
[XmlElement]
public List<string> IncludeObject {
get => _includeObject;
set => _includeObject = value.RemoveInvalidTokens();
}
[XmlAttribute]
public int MaxDuration {
get => _maxDuration;
set => _maxDuration = value.IsBetween(1, 10) ? value : _maxDuration;
}
[XmlAttribute]
public string NoRecompute {
get => _noRecompute;
set => _noRecompute = (value == DEFAULT || value == ON || value == OFF) ? value : _noRecompute;
}
[XmlAttribute]
public string DataCompression {
get => _dataCompression;
set => _dataCompression = (value == DEFAULT || value == NONE || value == "ROW" || value == "PAGE") ? value : _dataCompression;
}
[XmlAttribute]
public string AbortAfterWait {
get => _abortAfterWait;
set => _abortAfterWait = (value == NONE || value == "SELF" || value == "BLOCKERS") ? value : _abortAfterWait;
}
[XmlAttribute]
public string ScanMode {
get => _scanMode;
set => _scanMode = (value == LIMITED || value == "SAMPLED" || value == "DETAILED") ? value : _scanMode;
}
private void UpdateThreshold(int reorganize, int rebuild) {
_reorganizeThreshold = reorganize.IsBetween(0, 99) ? reorganize : _reorganizeThreshold;
_rebuildThreshold = rebuild.IsBetween(1, 100) ? rebuild : _rebuildThreshold;
if (_reorganizeThreshold > _rebuildThreshold)
_rebuildThreshold = _reorganizeThreshold + 1;
if (_reorganizeThreshold == _rebuildThreshold) {
if (_reorganizeThreshold > 0)
_reorganizeThreshold -= 1;
else
_rebuildThreshold += 1;
}
}
private void UpdateSize(int min, int pre, int max) {
_minIndexSize = min.IsBetween(0, 255) ? min : _minIndexSize;
_preDescribeSize = min.IsBetween(_minIndexSize, 256) ? pre : _preDescribeSize;
_maxIndexSize = max.IsBetween(512, 131072) ? max : _maxIndexSize;
if (_minIndexSize > _preDescribeSize)
_preDescribeSize = _minIndexSize + 1;
if (_minIndexSize == _maxIndexSize) {
if (_minIndexSize > 0)
_minIndexSize -= 1;
else
_maxIndexSize += 1;
}
}
public Options() {
SortInTempDb = true;
LobCompaction = true;
ScanHeap = true;
ScanClusteredIndex = true;
ScanNonClusteredIndex = true;
ScanClusteredColumnstore = true;
ScanNonClusteredColumnstore = true;
IgnorePermissions = true;
IgnoreReadOnlyFL = true;
}
}
}