Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Every Single Execution Plan Is an Estimated Plan

DZone's Guide to

Every Single Execution Plan Is an Estimated Plan

Hopefully, this helps people clarify what's up with execution plans and will help them put a little more faith in using the estimated plans in some cases.

· Database Zone ·
Free Resource

Running out of memory? Learn how Redis Enterprise enables large dataset analysis with the highest throughput and lowest latency while reducing costs over 75%! 

All the execution plans are estimated plans. All of them. There fundamentally isn't any such thing as an "actual" plan.

Where Do You Get Execution Plans?

There are a lot of sources for execution plans. You can capture them using extended events (or, if you must, trace). You can capture them through the Management Studio GUI. You can also capture them from the SQL Operations Studio GUI. You can query the cache through the DMV and pull them in that way. You can look at plans in query store.

All these resources, yet, for any given query, all the plans will be identical (assuming no recompile at work). Why? Because they're all the same plan. Each and every one of them is an estimated plan. Only an estimated plan. This is why the estimated costs stay the same between an estimated and actual plan despite any disparity between estimated and actual row counts.

I've blogged about this before, but it's worth mentioning again. There are only a few minor differences between an estimated plan and an actual plan. It's all about the dataset. What's going on is that an actual plan can capture query metrics, which are then appended to the estimated plan. At no point is any different plan generated during this process. It's just a plan, an estimated plan, or a plan plus query metrics.

Conclusion

Never mistake me on this, I want to see the query metrics as often as I can when dealing with execution plans. That means capturing what's called an actual plan. However, let's be clear: there's nothing different in that plan except those metrics. It's not a different plan. It's the same plan, plus some metrics. Hopefully, this helps people clarify what's up with execution plans and will help them put a little more faith in using the estimated plans in some cases.

Running out of memory? Never run out of memory with Redis Enterprise databaseStart your free trial today.

Topics:
database ,execution plan ,gui

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}