若僅是觀察 Execution Plan,例如,來自於 DMV: sys.dm_exec_query_plan 的資料行: query_plan。
該如何找到 原本輸入 的值呢?
方法是,在 Properties 視窗:
- 若被 SQL Server 「Simple Parameterization(簡單參數化)」,展開 Parameter List,在 Parameter Compiled Value,就可以看到 原先輸入的值。
或是: - 在 Statement,可以看到原先輸入執行 SQL 陳述式。

Look at parameter from execution plan, 查看執行 計畫 所使用的參數
01. Parameter List
01. 觀察 Parameter List - Execution Plan:
- SELECT * FROM Person.Address WHERE StateProvinceID=@1
- 原本輸入的值 32 ,經 SQL Server 使用 Simple Parameterization 功能,已參數為 @1 。
-- figure 01_Parameter List_Execution_Plan

02. 點選最左邊的 Operators (運算子): SELECT,滑鼠右鍵,選擇 Properties。
- 展開 Parameter List,在 Parameter Compiled Value,就可以看到原先輸入的值 32。
-- figure 02_Parameter_List

02. Statement
01. 觀察 Statement - Execution Plan:
- 兩個輸入值。
- SELECT * FROM Person.Address WHERE StateProvinceID=32 OR City='Baltimore'
-- figure 11_Statement_Execution_Plan

02. 在 Statement,可以看到原先輸入執行 SQL 陳述式。
-- figure 12_Statement

03. Parameter List
01. 觀察 Parameter List - Execution Plan:
- SELECT * FROM Person.Address WHERE StateProvinceID=@1 AND City=@2
- 原本輸入的值 32 與 'Baltimore' ,經 SQL Server 使用「Simple Parameterization(簡單參數化)」功能,已參數為 @1 與 @2。
-- figure 21_Parameter List_Execution_Plan

02. 點選最左邊的 Operators (運算子): SELECT,滑鼠右鍵,選擇 Properties。
- 展開 Parameter List,在 Parameter Compiled Value,就可以看到原先輸入的值 32 與 'Baltimore'。
-- figure 22_Parameter List

04. Parameter List: Stored Procedure
01. 觀察 Parameter List: Stored Procedure - Execution Plan:
- 可以看到該 Stored Procedure 內的 SQL 陳述式: WITH [BOM_cte] ...
-- figure 31_Parameter List_Stored Procedure

02. 點選最左邊的 Operators (運算子): SELECT,滑鼠右鍵,選擇 Properties。
- 展開 Parameter List,在 Parameter Compiled Value,就可以看到原先輸入的值 '2010-12-23' 與 819。
- 在 Statement,可以看到原先輸入 SQL 陳述式。
-- figure 32_Parameter List_Stored Procedure

範例程式碼
20171220_LookAtParameter
https://drive.google.com/drive/folders/0B9PQZW3M2F40OTk3YjI2NTEtNjUxZS00MjNjLWFkYWItMzg4ZDhhMGIwMTZl?usp=sharing
參考資料
[SQL Server] Look at Execution Plan and index: use Index Hint, WITH(FORCESEEK), Missing Index
http://sharedderrick.blogspot.tw/2017/12/sql-server-look-at-execution-plan-and.html
Update to expose maximum memory enabled for a single query in Showplan XML in SQL Server 2014 or 2016
https://support.microsoft.com/en-us/help/3170112/update-to-expose-maximum-memory-enabled-for-a-single-query-in-showplan
Simple Parameterization
https://technet.microsoft.com/en-us/library/ms186219(v=sql.105).aspx
沒有留言:
張貼留言