Performance Tuning

Silent Demo: The Plan Cache

Shhh, and pay close attention. In 76 seconds, I’ll teach you something intriguing about the way SQL Server caches execution plans:

Silent SQL Server Demo: The Plan Cache

Free, 3× a week

Get my new posts by email

Three posts a week, plus a Monday roundup of the best database news from around the web.

14 comments

  1. Hello Brent,

    Using your example, when I use the same query, I get two different execution plans. I thought SQL Server would not use a different execution plan, when the query is identical to the previous run?

    DBCC FREEPROCCACHE;
    GO
    SELECT COUNT(*) FROM dbo.Users;
    GO
    SELECT COUNT(*) FROM dbo.Users;
    GO
    sp_BlitzCache @HideSummary=1;

  2. I knew most of this, but what really surprised me is that even with the comment being after the semicolon it still generated a separate plan. I guess that means plans are generated per-batch instead of per-statement? I guess that makes sense, it’s just not what I expected.

      1. Yeah, neat is one word for it.

        I actually started considering using this on purpose to get around throwing a RECOMPILE hint on a query. I think I need a vacation.

  3. Hi Brent – At the end I presume you are using the American hand sign for two to say that there are 2 items in the plan cache – rather than the British two fingered version to express your opinion of the situation 🙂

    1. Yeah, remember what happened to the guy in “Inglorious Basterds” when he used the wrong hand signal for ‘three’. Eeek.

Leave a comment

Your email address will not be published. Required fields are marked *

Email me about new comments: