![](/img/trans.png)
[英]Get the query plan using jdbc PreparedStatement on sql server
[英]is it possible to get the query plan out using jdbc on sql server?
我正在使用JTDS驅動程序,我想確保我的java客戶端收到與在Mgmt studio中執行SQL時相同的查詢計划,有沒有辦法獲得查詢計划(理想情況下是xml格式)?
基本上,我想要相同的格式輸出
set showplan_xml on
在管理工作室。 有任何想法嗎?
一些用於獲取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 **/
@@SPID
或使用SSMS,查看Java客戶端會話的sys.dm_exec_sessions
和/或sys.dm_exec_connections
(可以通過program_name
, host_process_id
, client_net_address
等標識)。 sys.dm_exec_requests
中查找在1處找到的session_id
。 plan_handle
sys.dm_exec_query_plan
提取計划。 或者,您可以使用Profiler,將分析器附加到服務器並捕獲Showplan XML事件。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.