December 3, 2012 at 8:21 am
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
December 3, 2012 at 8:45 am
Could that query form part of a stored procedure that has a RECOMPILE hint either for the whole proc, or just that statement itself?
December 3, 2012 at 8:59 am
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
December 3, 2012 at 9:27 am
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
December 3, 2012 at 9:41 am
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
December 3, 2012 at 9:47 am
I am looking at the acitvity monitor...recent queries...plan count...I am assuming its the number of plans cached...can someone confirm?...
December 3, 2012 at 10:46 am
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
December 3, 2012 at 4:40 pm
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) "It's a dog-eat-dog world, and I'm wearing Milk-Bone underwear." "Norm", on "Cheers". Also from "Cheers", from "Carla": "You need to know 3 things about Tortelli men: Tortelli men draw women like flies; Tortelli men treat women like flies; Tortelli men's brains are in their flies".
December 3, 2012 at 6:13 pm
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