Query hash vs statement_sql_handle

sakuraime 2,306 Reputation points

there two columns from sys.dm_exec_requests call query_hash, and statement_sql_handle
from sys.dm_exec_query_stats also has these two columns .

may I know what's the actual difference from them ?

and also , from my server , I see a lot of entry that have query_hash , but not statement_sql_handle . why is that ?


SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
10,969 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. CathyJi-MSFT 20,986 Reputation points Microsoft Vendor

    Hi @sakuraime ,


    Binary hash value calculated on the query and used to identify queries with similar logic. You can use the query hash to determine the aggregate resource usage for queries that differ only by literal values.

    A query_hash is a computed value that points to a query irrespective of literal values.


    SQL handle of the individual query. This column is NULL if Query Store is not enabled for the database.

    Suggest you read this bog What is a query_hash or query_plan_hash and why is it useful to better understand this.

    If the response is helpful, please click "Accept Answer" and upvote it, as this could help other community members looking for similar queries.

  2. Erland Sommarskog 87,596 Reputation points

    may I know what's the actual difference from them ?

    Well, one is longer than the other...

    The SQL handle is an internal identifier and serves as an address in some DMVs, for instance sys.dm_sql_exec_text.

    The query_hash is computed from the "shape" of the query. Two queries that only differs in literal values have the same hash. When you analyse data, for instance in Query Store, queries that have the same query hash can be considered the same from a performance tuning perspective. The query_hash is only an aide for DBAs and similar, but not used internally.

    0 comments No comments