detecting query recompilation / sql server 2008

I'm trying to detect if I have some queries that are recompiling for requests from different users opposed to using cache. Here's how I plan on doing that:

USE DB

GO
DBCC dropcleanbuffers
DBCC freeproccache

GO

SET STATISTICS TIME ON

GO

SELECT STATEMENT

GO

SELECT STATEMENT

I realize that this will provide parse/compile and execution time.

The problem is that when User-A executes a particular query, it's slow at first and then fast after subsequent requests. When User-B executes that very same query, it's also slow at first and then faster after subsequent requests.

Will the foregoing be able to tell me whether or not the query is recompiled for User-B after it has compiled for User-A?

Ideally, I'm hoping that it'll compile for User-A and then just reference the existing plan/cache for User-B.

Will existing indexes impact this analysis? Should I drop them?
pae2Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Kevin CrossChief Technology OfficerCommented:
Try dynamic management view sys.dm_exec_query_stats and function sys.dm_exec_sql_text. In addition to demonstrating how to use the above, Pinal Dave does a nice job of describing how to reduce recompilation: http://blog.sqlauthority.com/2010/02/18/sql-server-plan-recompilation-and-reduce-recompilation-performance-tuning/.

One method is the KEEPFIXED PLAN hint: http://support.microsoft.com/kb/276220
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jogosCommented:
I hope you don't do the freecache/cleanbuffers on your production server. That is best only used on your local instance
0
Jim P.Commented:
I'm seeing your series of questions about monitoring performance. You may want to look at getting Confio's Ignite monitoring software. The free version gives you a fair amount of data like this.

http://www.confio.com/performance/sql-server/ignite/
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2008

From novice to tech pro — start learning today.