SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Cached Plan
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

shaggy
Posting Yak Master

India
245 Posts

Posted - 02/04/2013 :  02:27:02  Show Profile  Reply with Quote
1)sys.dm_exec_cached_plans
what is cached obhecttype as "prepared" ?
even though i execute stroed proc the object type for that is displayed as prepared, i suppose it should be proc

2)can i able to get the executed exec statement from cache?

3)plan reuse,It is ok to resue the same plan for different set of paramaeters

4)Instead of SP can i use adhoc query for single statement, it also has a same intelligence to resue plan.

James K
Flowing Fount of Yak Knowledge

3587 Posts

Posted - 02/04/2013 :  06:03:10  Show Profile  Reply with Quote
1. Not sure why cachobjtype is showing up us prepared. Is the next column (objtype) showing Proc? Also are you running the query from SSMS or from a client?

2. To get the text of the query, use this:
SELECT
	s.text,
	p.*
FROM
	sys.dm_exec_cached_plans p
	CROSS APPLY sys.dm_exec_sql_text (p.plan_handle) s


3. It is good, but sometimes bad. It is good because reusing query plans avoids the overhead of regenerating the query plan. But, sometimes, if the previously generated query plan is not a good fit for a new set of parameters, the query can turn out to be inefficient. If you google for "parameter sniffing" you will find information on this issue.

4. It is possible for adhoc queries to reuse plan (sometimes) - see a good discussion here: http://technet.microsoft.com/en-us/library/cc293623.aspx
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000