Skip to content

Commit e05bc69

Browse files
C8 expensive-operator carve-out + C9 columnstore on wide bare scans (#215) (#263)
C9: Rule 34 (Bare Scan) previously only fired when the scan output was ≤3 columns, since rowstore nonclustered indexes get expensive with more columns. Joe's point: columnstore (CCI/NCCI) doesn't care about column count, so a wide bare scan with nothing to suggest is a missed recommendation. Rule 34 now also fires on wide outputs (>3 columns) with columnstore-focused advice. Narrow-output path keeps the NC-index advice as before. C8: new Rule 35 "Expensive Operator" — emits when an operator's self- time is ≥20% of statement elapsed AND no other warning has already fired on the node. Ensures large work doesn't disappear just because the tool has nothing specific to suggest (Joe's scan-with-nothing-to-say case). Benefit % = self-time share; severity Critical at ≥50%, Warning otherwise. Self-guarded against existing warnings so it never stacks on top of a spill/lookup/etc. Neither rule fires on Joe's private plan (every significant operator already has a warning) or on 20260415_1.sqlplan (parallel work split). That's the expected "no false positives" behavior. Version bump 1.7.5 -> 1.7.6. Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 5731ae9 commit e05bc69

2 files changed

Lines changed: 50 additions & 10 deletions

File tree

‎src/PlanViewer.App/PlanViewer.App.csproj‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<ApplicationManifest>app.manifest</ApplicationManifest>
77
<ApplicationIcon>EDD.ico</ApplicationIcon>
88
<AvaloniaUseCompiledBindingsByDefault>true</AvaloniaUseCompiledBindingsByDefault>
9-
<Version>1.7.5</Version>
9+
<Version>1.7.6</Version>
1010
<Authors>Erik Darling</Authors>
1111
<Company>Darling Data LLC</Company>
1212
<Product>Performance Studio</Product>

‎src/PlanViewer.Core/Services/PlanAnalyzer.cs‎

Lines changed: 49 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -921,21 +921,38 @@ _ when nonSargableReason.StartsWith("Function call") =>
921921
? GetOperatorOwnElapsedMs(node) > 0
922922
: node.CostPercent >= 20;
923923

924-
if (colCount <= 3 && isSignificant)
924+
if (isSignificant)
925925
{
926926
var scanKind = node.PhysicalOp == "Clustered Index Scan"
927927
? "Clustered index scan"
928928
: "Heap table scan";
929-
var indexAdvice = node.PhysicalOp == "Clustered Index Scan"
930-
? "Consider a nonclustered index on the output columns (as key or INCLUDE) so SQL Server can read a narrower structure."
931-
: "Consider a clustered or nonclustered index on the output columns so SQL Server can read a narrower structure.";
932929

933-
node.Warnings.Add(new PlanWarning
930+
if (colCount <= 3)
934931
{
935-
WarningType = "Bare Scan",
936-
Message = $"{scanKind} reads the full table with no predicate, outputting {colCount} column(s): {Truncate(node.OutputColumns, 200)}. {indexAdvice} For analytical workloads, a columnstore index may be a better fit.",
937-
Severity = PlanWarningSeverity.Warning
938-
});
932+
// Narrow output: a nonclustered rowstore index can cover this cheaply.
933+
var indexAdvice = node.PhysicalOp == "Clustered Index Scan"
934+
? "Consider a nonclustered index on the output columns (as key or INCLUDE) so SQL Server can read a narrower structure."
935+
: "Consider a clustered or nonclustered index on the output columns so SQL Server can read a narrower structure.";
936+
937+
node.Warnings.Add(new PlanWarning
938+
{
939+
WarningType = "Bare Scan",
940+
Message = $"{scanKind} reads the full table with no predicate, outputting {colCount} column(s): {Truncate(node.OutputColumns, 200)}. {indexAdvice} For analytical workloads, a columnstore index may be a better fit.",
941+
Severity = PlanWarningSeverity.Warning
942+
});
943+
}
944+
else
945+
{
946+
// Wider output: rowstore NC index isn't a great fit (would have to
947+
// carry too many columns), but columnstore doesn't care about column
948+
// count. Suggest it for analytical / aggregate-style workloads.
949+
node.Warnings.Add(new PlanWarning
950+
{
951+
WarningType = "Bare Scan",
952+
Message = $"{scanKind} reads the full table with no predicate, outputting {colCount} columns. A nonclustered rowstore index isn't a great fit for wide outputs, but if this is an analytical or aggregate-style query, a columnstore index (CCI or NCCI) can scan the same data far more cheaply — column count doesn't penalize columnstore the way it does rowstore indexes.",
953+
Severity = PlanWarningSeverity.Warning
954+
});
955+
}
939956
}
940957
}
941958

@@ -1229,6 +1246,29 @@ _ when nonSargableReason.StartsWith("Function call") =>
12291246
w.Message = $"Implicit conversion prevented an index seek, forcing a scan instead. Fix the data type mismatch: ensure the parameter or variable type matches the column type exactly. {w.Message}";
12301247
}
12311248
}
1249+
1250+
// Rule 35: Expensive Operator — always show operators that take a significant
1251+
// share of statement time even when no other rule has something to say. Joe
1252+
// (#215 C8) wanted expensive scans that the tool had nothing to suggest on
1253+
// to still surface as top items. Threshold: self-time >= 20% of statement
1254+
// elapsed. Only emits if no other warning is already on the node to avoid
1255+
// doubling up. The benefit % is just the self-time share.
1256+
if (!cfg.IsRuleDisabled(35) && node.HasActualStats && node.Warnings.Count == 0
1257+
&& stmt.QueryTimeStats != null && stmt.QueryTimeStats.ElapsedTimeMs > 0)
1258+
{
1259+
var selfMs = GetOperatorOwnElapsedMs(node);
1260+
var pct = (double)selfMs / stmt.QueryTimeStats.ElapsedTimeMs * 100;
1261+
if (pct >= 20.0)
1262+
{
1263+
node.Warnings.Add(new PlanWarning
1264+
{
1265+
WarningType = "Expensive Operator",
1266+
Message = $"{node.PhysicalOp} took {selfMs:N0}ms ({pct:N1}% of statement elapsed) but no specific rule identified a fix. Worth investigating: is the row volume necessary? Are upstream estimates driving this operator harder than it should be?",
1267+
Severity = pct >= 50 ? PlanWarningSeverity.Critical : PlanWarningSeverity.Warning,
1268+
MaxBenefitPercent = Math.Round(Math.Min(100.0, pct), 1)
1269+
});
1270+
}
1271+
}
12321272
}
12331273

12341274
/// <summary>

0 commit comments

Comments
 (0)