-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathAnalysisResult.cs
More file actions
456 lines (327 loc) · 13 KB
/
AnalysisResult.cs
File metadata and controls
456 lines (327 loc) · 13 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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
using System.Text.Json.Serialization;
namespace PlanViewer.Core.Output;
/// <summary>
/// Top-level JSON output from plan analysis. Designed to be consumed by LLMs
/// and CI pipelines — everything needed to understand plan quality without
/// reading raw XML.
/// </summary>
public class AnalysisResult
{
[JsonPropertyName("plan_source")]
public string PlanSource { get; set; } = "";
[JsonPropertyName("sql_server_version")]
public string? SqlServerVersion { get; set; }
[JsonPropertyName("sql_server_build")]
public string? SqlServerBuild { get; set; }
[JsonPropertyName("statements")]
public List<StatementResult> Statements { get; set; } = new();
[JsonPropertyName("summary")]
public AnalysisSummary Summary { get; set; } = new();
[JsonPropertyName("server_context")]
public ServerContextResult? ServerContext { get; set; }
}
public class AnalysisSummary
{
[JsonPropertyName("total_statements")]
public int TotalStatements { get; set; }
[JsonPropertyName("total_warnings")]
public int TotalWarnings { get; set; }
[JsonPropertyName("critical_warnings")]
public int CriticalWarnings { get; set; }
[JsonPropertyName("missing_indexes")]
public int MissingIndexes { get; set; }
[JsonPropertyName("has_actual_stats")]
public bool HasActualStats { get; set; }
[JsonPropertyName("max_estimated_cost")]
public double MaxEstimatedCost { get; set; }
[JsonPropertyName("warning_types")]
public List<string> WarningTypes { get; set; } = new();
}
public class StatementResult
{
[JsonPropertyName("statement_text")]
public string StatementText { get; set; } = "";
[JsonPropertyName("statement_type")]
public string StatementType { get; set; } = "";
[JsonPropertyName("estimated_cost")]
public double EstimatedCost { get; set; }
[JsonPropertyName("estimated_rows")]
public double EstimatedRows { get; set; }
// Compilation metadata
[JsonPropertyName("optimization_level")]
public string? OptimizationLevel { get; set; }
[JsonPropertyName("early_abort_reason")]
public string? EarlyAbortReason { get; set; }
[JsonPropertyName("cardinality_estimation_model")]
public int CardinalityEstimationModel { get; set; }
[JsonPropertyName("compile_time_ms")]
public long CompileTimeMs { get; set; }
[JsonPropertyName("compile_memory_kb")]
public long CompileMemoryKB { get; set; }
[JsonPropertyName("cached_plan_size_kb")]
public long CachedPlanSizeKB { get; set; }
// Parallelism
[JsonPropertyName("degree_of_parallelism")]
public int DegreeOfParallelism { get; set; }
[JsonPropertyName("non_parallel_reason")]
public string? NonParallelReason { get; set; }
// Hashes for identification
[JsonPropertyName("query_hash")]
public string? QueryHash { get; set; }
[JsonPropertyName("query_plan_hash")]
public string? QueryPlanHash { get; set; }
// Memory grant
[JsonPropertyName("memory_grant")]
public MemoryGrantResult? MemoryGrant { get; set; }
// Runtime stats (actual plans only)
[JsonPropertyName("query_time")]
public QueryTimeResult? QueryTime { get; set; }
// Parameters
[JsonPropertyName("parameters")]
public List<ParameterResult> Parameters { get; set; } = new();
// Analysis results
[JsonPropertyName("warnings")]
public List<WarningResult> Warnings { get; set; } = new();
[JsonPropertyName("missing_indexes")]
public List<MissingIndexResult> MissingIndexes { get; set; } = new();
// Operator tree
[JsonPropertyName("operator_tree")]
public OperatorResult? OperatorTree { get; set; }
// Plan features
[JsonPropertyName("plan_guide")]
public string? PlanGuide { get; set; }
[JsonPropertyName("query_store_hint")]
public string? QueryStoreHint { get; set; }
[JsonPropertyName("trace_flags")]
public List<string> TraceFlags { get; set; } = new();
[JsonPropertyName("batch_mode_on_rowstore")]
public bool BatchModeOnRowStore { get; set; }
// Wait stats (actual plans only)
[JsonPropertyName("wait_stats")]
public List<WaitStatResult> WaitStats { get; set; } = new();
// Cursor metadata
[JsonPropertyName("cursor")]
public CursorResult? Cursor { get; set; }
}
public class MemoryGrantResult
{
[JsonPropertyName("requested_kb")]
public long RequestedKB { get; set; }
[JsonPropertyName("granted_kb")]
public long GrantedKB { get; set; }
[JsonPropertyName("max_used_kb")]
public long MaxUsedKB { get; set; }
[JsonPropertyName("grant_wait_ms")]
public long GrantWaitMs { get; set; }
[JsonPropertyName("feedback_adjusted")]
public string? FeedbackAdjusted { get; set; }
[JsonPropertyName("estimated_available_memory_grant_kb")]
public long EstimatedAvailableMemoryGrantKB { get; set; }
}
public class QueryTimeResult
{
[JsonPropertyName("cpu_time_ms")]
public long CpuTimeMs { get; set; }
[JsonPropertyName("elapsed_time_ms")]
public long ElapsedTimeMs { get; set; }
}
public class ParameterResult
{
[JsonPropertyName("name")]
public string Name { get; set; } = "";
[JsonPropertyName("data_type")]
public string DataType { get; set; } = "";
[JsonPropertyName("compiled_value")]
public string? CompiledValue { get; set; }
[JsonPropertyName("runtime_value")]
public string? RuntimeValue { get; set; }
[JsonPropertyName("sniffing_issue")]
public bool SniffingIssue { get; set; }
}
public class WarningResult
{
[JsonPropertyName("type")]
public string Type { get; set; } = "";
[JsonPropertyName("severity")]
public string Severity { get; set; } = "";
[JsonPropertyName("message")]
public string Message { get; set; } = "";
[JsonPropertyName("operator")]
public string? Operator { get; set; }
[JsonPropertyName("node_id")]
public int? NodeId { get; set; }
[JsonPropertyName("max_benefit_percent")]
public double? MaxBenefitPercent { get; set; }
[JsonPropertyName("actionable_fix")]
public string? ActionableFix { get; set; }
}
public class MissingIndexResult
{
[JsonPropertyName("table")]
public string Table { get; set; } = "";
[JsonPropertyName("impact")]
public double Impact { get; set; }
[JsonPropertyName("equality_columns")]
public List<string> EqualityColumns { get; set; } = new();
[JsonPropertyName("inequality_columns")]
public List<string> InequalityColumns { get; set; } = new();
[JsonPropertyName("include_columns")]
public List<string> IncludeColumns { get; set; } = new();
[JsonPropertyName("create_statement")]
public string CreateStatement { get; set; } = "";
}
public class OperatorResult
{
[JsonPropertyName("node_id")]
public int NodeId { get; set; }
[JsonPropertyName("physical_op")]
public string PhysicalOp { get; set; } = "";
[JsonPropertyName("logical_op")]
public string LogicalOp { get; set; } = "";
[JsonPropertyName("cost_percent")]
public int CostPercent { get; set; }
[JsonPropertyName("estimated_rows")]
public double EstimatedRows { get; set; }
[JsonPropertyName("estimated_cost")]
public double EstimatedCost { get; set; }
[JsonPropertyName("estimated_io")]
public double EstimatedIO { get; set; }
[JsonPropertyName("estimated_cpu")]
public double EstimatedCPU { get; set; }
[JsonPropertyName("estimated_row_size")]
public int EstimatedRowSize { get; set; }
// Object context
[JsonPropertyName("object_name")]
public string? ObjectName { get; set; }
[JsonPropertyName("index_name")]
public string? IndexName { get; set; }
[JsonPropertyName("database_name")]
public string? DatabaseName { get; set; }
// Predicates — key for understanding what the operator does
[JsonPropertyName("seek_predicates")]
public string? SeekPredicates { get; set; }
[JsonPropertyName("predicate")]
public string? Predicate { get; set; }
[JsonPropertyName("output_columns")]
public string? OutputColumns { get; set; }
// Join details
[JsonPropertyName("hash_keys_build")]
public string? HashKeysBuild { get; set; }
[JsonPropertyName("hash_keys_probe")]
public string? HashKeysProbe { get; set; }
[JsonPropertyName("outer_references")]
public string? OuterReferences { get; set; }
// Sort/aggregate
[JsonPropertyName("order_by")]
public string? OrderBy { get; set; }
[JsonPropertyName("group_by")]
public string? GroupBy { get; set; }
// Parallelism
[JsonPropertyName("parallel")]
public bool Parallel { get; set; }
[JsonPropertyName("execution_mode")]
public string? ExecutionMode { get; set; }
[JsonPropertyName("actual_execution_mode")]
public string? ActualExecutionMode { get; set; }
// Actual stats (when available)
[JsonPropertyName("actual_rows")]
public long? ActualRows { get; set; }
[JsonPropertyName("actual_executions")]
public long? ActualExecutions { get; set; }
[JsonPropertyName("actual_elapsed_ms")]
public long? ActualElapsedMs { get; set; }
[JsonPropertyName("actual_cpu_ms")]
public long? ActualCpuMs { get; set; }
[JsonPropertyName("actual_logical_reads")]
public long? ActualLogicalReads { get; set; }
[JsonPropertyName("actual_physical_reads")]
public long? ActualPhysicalReads { get; set; }
// Warnings on this operator
[JsonPropertyName("warnings")]
public List<WarningResult> Warnings { get; set; } = new();
// Children
[JsonPropertyName("children")]
public List<OperatorResult> Children { get; set; } = new();
}
public class WaitStatResult
{
[JsonPropertyName("wait_type")]
public string WaitType { get; set; } = "";
[JsonPropertyName("wait_time_ms")]
public long WaitTimeMs { get; set; }
[JsonPropertyName("wait_count")]
public long WaitCount { get; set; }
}
public class CursorResult
{
[JsonPropertyName("name")]
public string? Name { get; set; }
[JsonPropertyName("actual_type")]
public string? ActualType { get; set; }
[JsonPropertyName("requested_type")]
public string? RequestedType { get; set; }
[JsonPropertyName("concurrency")]
public string? Concurrency { get; set; }
[JsonPropertyName("forward_only")]
public bool ForwardOnly { get; set; }
}
public class ServerContextResult
{
[JsonPropertyName("server_name")]
public string? ServerName { get; set; }
[JsonPropertyName("product_version")]
public string? ProductVersion { get; set; }
[JsonPropertyName("product_level")]
public string? ProductLevel { get; set; }
[JsonPropertyName("edition")]
public string? Edition { get; set; }
[JsonPropertyName("is_azure")]
public bool IsAzure { get; set; }
[JsonPropertyName("cpu_count")]
public int CpuCount { get; set; }
[JsonPropertyName("physical_memory_mb")]
public long PhysicalMemoryMB { get; set; }
[JsonPropertyName("max_dop")]
public int MaxDop { get; set; }
[JsonPropertyName("cost_threshold_for_parallelism")]
public int CostThresholdForParallelism { get; set; }
[JsonPropertyName("max_server_memory_mb")]
public long MaxServerMemoryMB { get; set; }
[JsonPropertyName("database")]
public DatabaseContextResult? Database { get; set; }
}
public class DatabaseContextResult
{
[JsonPropertyName("name")]
public string Name { get; set; } = "";
[JsonPropertyName("compatibility_level")]
public int CompatibilityLevel { get; set; }
[JsonPropertyName("collation")]
public string CollationName { get; set; } = "";
// Isolation
[JsonPropertyName("snapshot_isolation_state")]
public int SnapshotIsolationState { get; set; }
[JsonPropertyName("read_committed_snapshot")]
public bool ReadCommittedSnapshot { get; set; }
// Stats
[JsonPropertyName("auto_create_stats")]
public bool AutoCreateStats { get; set; }
[JsonPropertyName("auto_update_stats")]
public bool AutoUpdateStats { get; set; }
[JsonPropertyName("auto_update_stats_async")]
public bool AutoUpdateStatsAsync { get; set; }
// Parameterization
[JsonPropertyName("parameterization_forced")]
public bool ParameterizationForced { get; set; }
[JsonPropertyName("non_default_scoped_configs")]
public List<ScopedConfigResult> NonDefaultScopedConfigs { get; set; } = new();
}
public class ScopedConfigResult
{
[JsonPropertyName("name")]
public string Name { get; set; } = "";
[JsonPropertyName("value")]
public string Value { get; set; } = "";
[JsonPropertyName("value_for_secondary")]
public string? ValueForSecondary { get; set; }
}