What is the Difference Between sql_handle and plan_handle?- Interview Question of the Week #269


 

Question: What is the Difference Between sql_handle and plan_handle?

Answer: I was recently asked this question during the Comprehensive Database Performance Health Check. Before we see the answer to this question, let us see where actually you can find the columns sql_handle and plan_handle.

If you run the following query you will find the columns sql_handle and plan_handle.

SELECT sql_handle, plan_handle FROM sys.dm_exec_query_stats

SQL Handle: It is a hash of the SQL Text containing all of your formatting (casing, spaces, etc).

Plan Handle: It is a hash of the execution plan build from a SQL.

In simple words: sql_handle is the source code, and the