Randy Minder
Randy Minder

Reputation: 48402

SQL Server Execution Plans - Actual vs. Estimated

I am reading Grant Fritchey's excellent book, SQL Server Execution Plans. On pg. 21 he states, "When a query is submitted to the server, an estimated execution plan is created by the optimizer. Once that plan is created, and before it gets passed to the storage engine, the optimizer compares this estimated plan to the actual execution plan that already exist in the plan cache." He goes on to say that this is done because it's expensive to generate query plans.

This sounds like SQL Sever will calculate an estimated plan, by the optimizer, and, if the estimated plan doesn't match an actual plan in the plan cache, create an actual plan and store it in the cache. So, it sounds like whether an existing plan exists in the plan cache or not, SQL Server will always generate an estimated plan. If it's going to do this anyway, why bother storing anything in a cache? Why not just always calculate a plan, since it's going to do it at least once anyway? Am I missing something?

Thanks.

Upvotes: 2

Views: 2097

Answers (1)

gbn
gbn

Reputation: 432210

I'd read this which is more accurate, IMHO

Grant's take is here too

Upvotes: 1

Related Questions