Skip to content
Merged
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
12 changes: 8 additions & 4 deletions src/PlanViewer.Core/Services/PlanAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -600,15 +600,19 @@

// Rule 8: Parallel thread skew (actual plans with per-thread stats)
// Only warn when there are enough rows to meaningfully distribute across threads
// Filter out thread 0 (coordinator) which typically does 0 rows in parallel operators
if (!cfg.IsRuleDisabled(8) && node.PerThreadStats.Count > 1)
{
var totalRows = node.PerThreadStats.Sum(t => t.ActualRows);
var minRowsForSkew = node.PerThreadStats.Count * 1000;
var workerThreads = node.PerThreadStats.Where(t => t.ThreadId > 0).ToList();
if (workerThreads.Count < 2) workerThreads = node.PerThreadStats; // fallback
var totalRows = workerThreads.Sum(t => t.ActualRows);
var minRowsForSkew = workerThreads.Count * 1000;
if (totalRows >= minRowsForSkew)
{
var maxThread = node.PerThreadStats.OrderByDescending(t => t.ActualRows).First();
var maxThread = workerThreads.OrderByDescending(t => t.ActualRows).First();
var skewRatio = (double)maxThread.ActualRows / totalRows;
var skewThreshold = node.PerThreadStats.Count == 2 ? 0.75 : 0.50;
// At DOP 2, a 60/40 split is normal — use higher threshold
var skewThreshold = workerThreads.Count <= 2 ? 0.80 : 0.50;
if (skewRatio >= skewThreshold)
{
var message = $"Thread {maxThread.ThreadId} processed {skewRatio:P0} of rows ({maxThread.ActualRows:N0}/{totalRows:N0}). Work is heavily skewed to one thread, so parallelism isn't helping much.";
Expand Down Expand Up @@ -939,7 +943,7 @@
// Rule 28: Row Count Spool — NOT IN with nullable column
// Pattern: Row Count Spool with high rewinds, child scan has IS NULL predicate,
// and statement text contains NOT IN
if (!cfg.IsRuleDisabled(28) && node.PhysicalOp.Contains("Row Count Spool"))

Check warning on line 946 in src/PlanViewer.Core/Services/PlanAnalyzer.cs

View workflow job for this annotation

GitHub Actions / build-and-test

Dereference of a possibly null reference.

Check warning on line 946 in src/PlanViewer.Core/Services/PlanAnalyzer.cs

View workflow job for this annotation

GitHub Actions / build-and-test

Dereference of a possibly null reference.
{
var rewinds = node.HasActualStats ? (double)node.ActualRewinds : node.EstimateRewinds;
if (rewinds > 10000 && HasNotInPattern(node, stmt))
Expand Down
Loading