I am using the JTDS driver and I'd like to make sure my java client is receiving the same query plan as when I execute the SQL in Mgmt studio, is there a way to get the query plan (ideally in xml format)?
basically, I'd like the same format output as
set showplan_xml on
in management studio. Any ideas?
Cheers,
-James
Some code for getting the plan for a session_id
SELECT usecounts, cacheobjtype,
objtype, [text], query_plan
FROM sys.dm_exec_requests req, sys.dm_exec_cached_plans P
CROSS APPLY
sys.dm_exec_sql_text(plan_handle)
CROSS APPLY
sys.dm_exec_query_plan(plan_handle)
WHERE cacheobjtype = 'Compiled Plan'
AND [text] NOT LIKE '%sys.dm_%'
--and text like '%sp%reassign%'
and p.plan_handle = req.plan_handle
and req.session_id = 70 /** <-- your sesssion_id here **/