plant count really high-Activity Monitor

  • Hi

    I am new to the DBA side, but activity montior shows a high plan clount of 23438

    The query that an application runs is :

    SELECT *

    FROM Trans_Events

    WHERE iTrans_fk = 1604855

    Itrans_fk is non-clustered index and no fragmentation on the table.

    can anyone point me in the right direction?

    Thanks

  • Could that query form part of a stored procedure that has a RECOMPILE hint either for the whole proc, or just that statement itself?



    MCSE: Data Platform
    MCSE: Business Intelligence
    Follow me on Twitter: @WazzTheBadger
    LinkedIn Profile: Simon Osborne

  • I'm a little confused by the question. When you say "high plan count" do you mean the number of plans in cache is high? If that's right, how are you establishing a low & high number there. Do you have a baseline.

    Or, do you mean that the query is running long? If so, you need to look at the execution plan to understand whether or not it's selecting the index that you have. Also, since you're doing a SELECT * and you're going against a non-clustered index, you're going to be seeing RID or key lookups (depending on if you're dealing with a heap or a clustered index).

    Or, do you mean that the estimated rows is high? If so, you need to update your statistics.

    "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

  • It is a query that is running not a store proc, but runs very often.....The table does have a clustered index, but the search is done on a non-clustered index...I got the plan count from activity monitor>Recent Expensive Queries

    Update stats is auto on the DB

    I dont have a baseline but isn't 23000+ a really high plan count. The query executes within a second.

    Maybe I need a better understanding of plan counts, can you please explan?

    Thanks

  • I'm still confused. Is that 23,000 executions of a query, or 23,000 different query plans of a query? You keep saying "plan count" and that's where my confusion lies. If it's 23,000 plans, you have some major issues.

    "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

  • I am looking at the acitvity monitor...recent queries...plan count...I am assuming its the number of plans cached...can someone confirm?...

  • Yes, that's an indication that you're probably using dynamic or ad hoc queries and every single variation of the parameter values is resulting in a different execution plan. That's really, really, bad. You're going to be hurting seriously with regards to memory and plan caching. You need to look at parameterizing the query in order to avoid this issue. That can be done by executing it using sp_executesql or by using prepared statements from your code or by creating a stored procedure.

    "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

  • Hmm, something seems odd.

    SQL should be able to easily do "simple parameterization" -- the old name, "auto-parameterization", seems clearer to me -- on that query. That is, SQL should automatically convert the query to make the value in the WHERE clause a parameter so a shareable plan is created.

    Are you changing the case (upper/lower) of the query each time?(??)

    Or making some other noticeable change to the query each time?

    SQL DBA,SQL Server MVP(07, 08, 09) A socialist is someone who will give you the shirt off *someone else's* back.

  • ScottPletcher (12/3/2012)


    Hmm, something seems odd.

    SQL should be able to easily do "simple parameterization" -- the old name, "auto-parameterization", seems clearer to me -- on that query. That is, SQL should automatically convert the query to make the value in the WHERE clause a parameter so a shareable plan is created.

    Are you changing the case (upper/lower) of the query each time?(??)

    Or making some other noticeable change to the query each time?

    But if there were significant changes then it's likely the hash for the query (which is what this must be using) would be different. They're the same.

    You could try forced parameterization. You could also try using Optimize for Ad Hoc. You certainly sound like a candidate.

    "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

Viewing 9 posts - 1 through 8 (of 8 total)

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