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
6 changes: 3 additions & 3 deletions src/PlanViewer.App/Controls/QueryStoreGridControl.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -462,9 +462,9 @@ private void OnWaitStatsCollapsedChanged(object? sender, bool collapsed)

if (!collapsed && _slicerStartUtc.HasValue && _slicerEndUtc.HasValue)
{
// Re-fetch wait stats when expanding
var cts = new CancellationTokenSource();
_ = FetchWaitStatsAsync(_slicerStartUtc.Value, _slicerEndUtc.Value, cts.Token);
// Re-fetch wait stats when expanding — reuse the shared CTS
var ct = _fetchCts?.Token ?? CancellationToken.None;
_ = FetchWaitStatsAsync(_slicerStartUtc.Value, _slicerEndUtc.Value, ct);
}
}

Expand Down
15 changes: 7 additions & 8 deletions src/PlanViewer.Core/Services/QueryStoreService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -473,14 +473,13 @@ JOIN sys.query_store_runtime_stats_interval rsi
return rows;
}

/// <summary>
/// Per-plan wait stats aggregated for a time range, grouped by plan_id + category.
/// WaitRatio = SUM(total_query_wait_time_ms) / sum(rs.avg_duration*rs.count_executions)
/// ==> May be challenged. But at the detail level we use the plan duration use query stats.
/// So it is different from the other wait ratio calculation, which is based on the interval duration.
/// We can consider to align them in the future if needed.
/// </summary>
public static async Task<List<(long PlanId, WaitCategoryTotal Wait)>> FetchPlanWaitStatsAsync(
/// <summary>
/// Per-plan wait stats aggregated for a time range, grouped by plan_id + category.
/// WaitRatio = SUM(total_query_wait_time_ms) / SUM(avg_duration * count_executions).
/// This differs from the global/hourly WTR (which divides by wall-clock interval) because
/// at plan level we measure what fraction of actual execution time was spent waiting.
/// </summary>
public static async Task<List<(long PlanId, WaitCategoryTotal Wait)>> FetchPlanWaitStatsAsync(
string connectionString, DateTime startUtc, DateTime endUtc,
CancellationToken ct = default)
{
Expand Down
Loading