Skip to content

Expensive Operators Plan Cache Wide: Where to Look

We see this in shop after shop. CPU climbs month over month, nobody deployed anything dramatic, and every query someone opens looks a little wasteful but not guilty. The team wants to know about expensive operators plan cache wide. What they have is one plan at a time.

How do I find expensive operators plan cache wide in SQL Server? To find expensive operators plan cache wide, take each operator's own estimated cost, multiply it by how often its plan runs each day, and add the results by operator type, table and plan. This shows whether scans, sorts, lookups or spools carry the workload, and which tables to tune first.

Database Health Monitor has a report for that gap, called Plan Operator Census. First, though, the habit it replaces.

Why the top query list misleads

Most people sort queries by CPU, open the first few, and fix whatever looks ugly. It feels productive. Sometimes it is.

The trouble is that a ranking of statements hides anything spread thinly across many of them. Picture one table scanned by dozens of different procedures. No single procedure makes the top five, yet together those scans may outweigh the query you spent Thursday rewriting. A tuning checklist would catch the scan in any one of those plans, if somebody happened to open it.

Percentages inside a graphical plan mislead too. An operator showing most of the cost of a statement that runs twice a day matters far less than a modest one running all day long. The share is relative to its own statement, and it says nothing about frequency.

Plan Operator Census is one of the reports in Database Health Monitor. It runs against your own servers, and it takes about a minute to have this same screen open on one of them.

The number worth adding up

Two things belong together. The first is an operator's own cost, meaning its subtree cost minus whatever the operators beneath it account for. Without that subtraction, a parent gets blamed for its children. The second is how many times a day the plan runs. Multiply them, then sum across every statement you read.

One caution, and it matters. This is the optimizer's estimate, not measured time. It ranks what SQL Server believed the work would cost when it chose the plan. Hold it next to your measured CPU, and where the two disagree sharply, be curious before you act. For a view built from reads instead, see Logical Reads Per Row: Which Query Reads Too Much?

What the census puts on screen

The report walks every operator in each statement plan it reads, taking the busiest 500, 1000 or 2500 statements by CPU. One pass, three views:

  • By operator: families such as Scan, Seek, Lookup, Sort, Hash Match, Spool and Scalar UDF, each with its share and weighted cost per day.
  • By table: cost split into Scan, Seek, Lookup and Write, beside row count, size and the index names seen.
  • By plan: each plan's single costliest operator, with the statement, where it lives, and runs per day.

Double click a family to see which tables it hits. Double click a table to see its plans. That path, from "we sort too much" to the exact statement, is where the hours get saved.

The table view is usually where we would begin. Tables under 1,000 rows are marked as small, because scanning them costs little in practice, and you can hide them so they stop distracting you. Key Lookups get their own family, whatever join sits above them, and the plan view names the index that needs the missing columns added as included columns.

Know the limits before you quote a number to a manager. The plan cache is a sample, and evicted plans are gone. Query Store covers the last 24 hours, including plans no longer cached, so prefer it when it is on. Plans over 4 MB are skipped and counted. You need SQL Server 2008 or newer, and 2016 or newer for the Query Store source. The Plan Operator Census reference covers every column.

Then pick one table. Fix the heaviest thing happening to it, whether that is a lookup wanting an included column or a scan wanting a better index, and read the census again once the new plans have had time to run. For a business paying for cores, knowing which change to make first is worth far more than a long list of things that merely look untidy. If the ranking points somewhere your team does not want to touch alone, that is a good moment to ask for a second pair of eyes.

What to check on your own server

  • Check that your login has VIEW SERVER STATE, because the plan cache cannot be read without it
  • Check whether Query Store is on, since it keeps plans that have already left the cache
  • Rank your tables by estimated operator cost times daily executions, setting aside those under 1,000 rows
  • Open the plan behind the costliest Key Lookup and note which columns the neighboring index is missing
  • Compare that ranking with your measured CPU before you change any index

Try Database Health Monitor Today

You know the server is burning CPU, but you cannot say whether scans, sorts or lookups are responsible, or on which tables. Database Health Monitor shows it on every instance you connect, in the time it takes to open the report.

Download Database Health Monitor and run the Plan Operator Census report against your own server. There is nothing to configure first, and you will know inside a few minutes whether it tells you something you did not already know.

Related reading: Foreign Key Performance: Read the Priority Column First. If parent deletes or key updates feel slower than they should, our walkthrough of the Foreign Keys report shows which keys to deal with first and which can wait.

Related reading: Sometimes Slow Query SQL Server Averages Can Hide. When users say a statement is only slow now and then, the spread between its average and worst run in the plan cache shows where to look first.