Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/PlanViewer.Core/Output/AnalysisResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,20 @@ public class MemoryGrantResult

[JsonPropertyName("estimated_available_memory_grant_kb")]
public long EstimatedAvailableMemoryGrantKB { get; set; }

/// <summary>
/// Optimizer's pre-execution "desired" grant (parallel-adjusted).
/// Non-zero on estimated plans; pairs with DesiredKB serial-required as fallback
/// when no runtime-granted memory exists (#215 E6).
/// </summary>
[JsonPropertyName("desired_kb")]
public long DesiredKB { get; set; }

/// <summary>
/// Optimizer's pre-execution serial-required grant (memory minimum before DOP scaling).
/// </summary>
[JsonPropertyName("serial_required_kb")]
public long SerialRequiredKB { get; set; }
}

public class QueryTimeResult
Expand Down
7 changes: 7 additions & 0 deletions src/PlanViewer.Core/Output/HtmlExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,13 @@ private static void WriteRuntimeCard(StringBuilder sb, StatementResult stmt)
var spillTag = hasSpill ? " <span class=\"spill-tag\" title=\"Operators spilled to tempdb\">⚠ spill</span>" : "";
sb.AppendLine($"<div class=\"row\"><span class=\"label\">Used</span><span class=\"value {effClass}\">{FormatKB(stmt.MemoryGrant.MaxUsedKB)} ({pctUsed:N0}%){spillTag}</span></div>");
}
else if (isEstimated && stmt.MemoryGrant != null && stmt.MemoryGrant.DesiredKB > 0)
{
// #215 E6: estimated plans — show the optimizer's pre-execution desired grant
WriteRow(sb, "Memory (estimated)", FormatKB(stmt.MemoryGrant.DesiredKB) + " desired");
if (stmt.MemoryGrant.SerialRequiredKB > 0 && stmt.MemoryGrant.SerialRequiredKB != stmt.MemoryGrant.DesiredKB)
WriteRow(sb, "Serial required", FormatKB(stmt.MemoryGrant.SerialRequiredKB));
}
if (stmt.OptimizationLevel != null)
WriteRow(sb, "Optimization", Encode(stmt.OptimizationLevel));
if (stmt.CardinalityEstimationModel > 0)
Expand Down
4 changes: 3 additions & 1 deletion src/PlanViewer.Core/Output/ResultMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,9 @@ private static StatementResult MapStatement(PlanStatement stmt)
MaxUsedKB = stmt.MemoryGrant.MaxUsedMemoryKB,
GrantWaitMs = stmt.MemoryGrant.GrantWaitTimeMs,
FeedbackAdjusted = stmt.MemoryGrant.IsMemoryGrantFeedbackAdjusted,
EstimatedAvailableMemoryGrantKB = stmt.HardwareProperties?.EstimatedAvailableMemoryGrant ?? 0
EstimatedAvailableMemoryGrantKB = stmt.HardwareProperties?.EstimatedAvailableMemoryGrant ?? 0,
DesiredKB = stmt.MemoryGrant.DesiredMemoryKB,
SerialRequiredKB = stmt.MemoryGrant.SerialRequiredMemoryKB
};
}

Expand Down
14 changes: 14 additions & 0 deletions src/PlanViewer.Web/Pages/Index.razor
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,20 @@ else
</span>
</div>
}
else if (isEstimatedRuntime && ActiveStmt!.MemoryGrant != null && ActiveStmt!.MemoryGrant.DesiredKB > 0)
{
<div class="insight-row">
<span class="insight-label">Memory (estimated)</span>
<span class="insight-value">@FormatKB(ActiveStmt!.MemoryGrant.DesiredKB) desired</span>
</div>
@if (ActiveStmt!.MemoryGrant.SerialRequiredKB > 0 && ActiveStmt!.MemoryGrant.SerialRequiredKB != ActiveStmt!.MemoryGrant.DesiredKB)
{
<div class="insight-row">
<span class="insight-label">Serial required</span>
<span class="insight-value">@FormatKB(ActiveStmt!.MemoryGrant.SerialRequiredKB)</span>
</div>
}
}
@if (ActiveStmt!.OptimizationLevel != null)
{
<div class="insight-row">
Expand Down
Loading