question

sakuraime avatar image
0 Votes"
sakuraime asked ErlandSommarskog answered

Query hash vs statement_sql_handle

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 ?

Thanks

sql-server-general
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Cathyji-msft avatar image
0 Votes"
Cathyji-msft answered sakuraime commented

Hi @sakuraime,

query_hash

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.

statement_sql_handle

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
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

hi . query is enabled already

0 Votes 0 ·

Hi I mean query store is enabled already

0 Votes 0 ·
ErlandSommarskog avatar image
0 Votes"
ErlandSommarskog answered

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.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.