Why the cost percentages in SQL Server plans are always estimates, the cases where they lie badly (bad cardinality, scalar UDFs, remote calls, parallelism), and how to find the real hotspot.
The cost percentages are the optimiser's estimated costs, even in an actual plan; they are never recalculated from run time. If an operator was estimated at 10 rows and processed a million, it still shows a tiny percentage. Some work is costed close to nothing: scalar UDFs run per row, remote/linked-server calls and multi-statement TVFs get fixed guesses. Parallel plans divide CPU cost by DOP, which can make a heavy branch look cheap. So I compare estimated vs actual rows and executions, read the per-operator actual elapsed time, CPU and logical reads in the actual plan, and confirm with SET STATISTICS IO, TIME.
Why they mislead. The optimiser assigns each operator a cost from its cost model: estimated rows × row size × CPU and I/O constants. The plan's percentages are each operator's share of that estimated total. An actual plan adds runtime counters (actual rows, executions, elapsed time, CPU, reads) but does not recompute the costs. So:
What I do instead.
SET STATISTICS IO, TIME ON for reads per table and CPU vs elapsed.sys.dm_exec_function_stats and whether scalar UDF inlining (compat 150+) applies.sys.dm_exec_query_plan_stats (last actual plan) and Query Store for CPU, duration and reads over time.Example. An EF Core report took 40 s and the plan said 85% was a Clustered Index Scan. The scan's actual time was 300 ms. The real cost was a scalar UDF in a computed column, shown as a 0% Compute Scalar, that read another table for each of 600,000 rows. Rewriting it as a join cut the query to 1.2 s.
Checks that they know costs are always estimates and how to measure real work.
Green flags: says percentages are estimated even in actual plans; uses estimated vs actual rows and executions; knows UDFs, remote calls and TVFs hide work; mentions parallel costing; confirms with STATISTICS IO/TIME or Query Store.
Red flags: goes straight for the highest percentage; thinks cost is milliseconds; never mentions actual rows; unaware of per-operator runtime stats.
The cost model. Costs are in abstract units calibrated decades ago (roughly seconds on a 1990s reference machine). Each operator has I/O cost (pages, random vs sequential) and CPU cost (per row). Subtree cost is the sum of children plus self. The optimiser uses these only to compare alternatives during optimisation; they are not predictions of time.
Parallel costing. For parallel plans the CPU cost of operators in the parallel zone is divided by DOP (capped by the number of schedulers the optimiser assumes, often half the cores visible for costing); I/O cost is not reduced. cost threshold for parallelism compares against the serial plan's cost. This is why a parallel plan may be chosen with a lower total cost, and why its per-operator percentages don't line up with serial expectations.
Runtime counters. Since SQL Server 2016 SP1 (and 2014 SP2), actual plans include RunTimeCountersPerThread with ActualElapsedms, ActualCPUms, ActualLogicalReads and ActualPhysicalReads. In row mode, elapsed time is cumulative including children; in batch mode it is per operator — read carefully.
Scalar UDF inlining. At compat 150+, eligible scalar UDFs (no time-dependent functions, no table variables with side effects, and so on) are inlined into the calling query as relational expressions, so they are costed and parallelisable. sys.sql_modules.is_inlineable tells you which.
Lightweight profiling. LAST_QUERY_PLAN_STATS (database scoped config) lets sys.dm_exec_query_plan_stats return the last actual plan with low overhead.
SET STATISTICS IO, TIME ON;
SELECT o.OrderId, dbo.fn_CustomerTier(o.CustomerId) AS Tier -- per-row UDF
FROM dbo.Orders AS o
WHERE o.CreatedAt >= '2026-11-01';
SET STATISTICS IO, TIME OFF;
-- Hidden UDF work
SELECT OBJECT_NAME(object_id) AS fn, execution_count,
total_worker_time / 1000 AS cpu_ms, total_logical_reads
FROM sys.dm_exec_function_stats
WHERE database_id = DB_ID();
-- Can it be inlined (compat 150+)?
SELECT OBJECT_NAME(object_id) AS fn, is_inlineable
FROM sys.sql_modules
WHERE object_id = OBJECT_ID(N'dbo.fn_CustomerTier');
-- Last actual plan for a cached query (needs LAST_QUERY_PLAN_STATS = ON)
SELECT qps.query_plan
FROM sys.dm_exec_cached_plans AS cp
CROSS APPLY sys.dm_exec_query_plan_stats(cp.plan_handle) AS qps;
-- Rewrite: the UDF's lookup as a join
SELECT o.OrderId, c.Tier
FROM dbo.Orders AS o
JOIN dbo.CustomerTiers AS c ON c.CustomerId = o.CustomerId
WHERE o.CreatedAt >= '2026-11-01';
I treat the cost percentages as the optimiser's opinion, useful for understanding why it chose the plan, not where the time went. To find where the time went I need measurements: actual rows and executions per operator, actual time and reads, and Query Store over many executions. The biggest wins come from the places the optimiser was wrong — the estimate gaps — and from work it can't see, like UDFs and remote calls. In code review I flag scalar UDFs in SELECT lists and WHERE clauses for exactly this reason.
Last updated 23 Nov 2026.