Does EF4 reuse query plans?

  • Does anyone have any experience with EF4 and the queries it generates? Someone from the application team mentioned that the query plans were reused (somehow). Is this true?

  • Nevermind, it does use cached plans.

    Found an interesting article that helped answer my question.

    http://awanderingmind.com/2011/01/03/entity-framework-from-a-dba-perspective-part-2/

  • vishal.gamji (4/22/2011)


    Does anyone have any experience with EF4 and the queries it generates? Someone from the application team mentioned that the query plans were reused (somehow). Is this true?

    By EF4, I assume you mean Entity Framework version 4? If not, what I'm about to say is not applicable.

    Yes, the queries generated by EF4 can be reused. They are parameterized queries, which are, effectively, the same as stored procedures. The query plan gets stored in cache with parameters, not hard coded values, so when the same call comes through but with different values, a plan can be reused. That said, You're still better setting Optimize For Ad Hoc Workloads to on, so that the first time a query is called only a plan stub is stored as opposed to an entire plan. This is helpful because, while the queries can be reused, there's no guarantee they will be. This is because the nature of the code is such that if two parameters are called one time, you get a plan with two parameters. But if the next call only uses a single parameter, it gets rebuilt as a query with one parameter, which means a second plan in cache.

    "The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
    - Theodore Roosevelt

    Author of:
    SQL Server Execution Plans
    SQL Server Query Performance Tuning

  • vishal.gamji (4/22/2011)


    Nevermind, it does use cached plans.

    Found an interesting article that helped answer my question.

    http://awanderingmind.com/2011/01/03/entity-framework-from-a-dba-perspective-part-2/

    Good. Guess I need to type faster next time.

    "The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
    - Theodore Roosevelt

    Author of:
    SQL Server Execution Plans
    SQL Server Query Performance Tuning

  • Thank you.

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply