What is a query_hash or query_plan_hash and why is it useful?

If you have ever queried sys.dm_exec_requests or sys.dm_exec_query_stats you may have noticed the query_hash and query_plan_hash columns.  If you’re familiar with a sql_handle and plan_handle the query_hash and query_plan_hash should be easy to understand.  A query_hash is a computed value that points to a query irrespective of literal values.  Similarly a query_plan_hash is a computed […]

Read More

Your plan is cached but dm_exec_query_plan returns NULL, Why?

On occasion you might query sys.dm_exec_query_plan with a valid plan_handle and it will return NULL for the query_plan column.  This is despite seeing the plan_handle in sys.dm_exec_query_stats, sys.dm_exec_procedure_stats, or sys.dm_exec_cached_plans.  In this short post I’ll explain how to replicate this behavior and why you might see it. Replicating For this example I’ll be using a […]

Read More

Do you have unused indexes?

Having the proper indexes in place is important for performance; however, on occasion indexes are created that are never used. Unnecessary indexes incur overhead for any DML. Fortunately this is a simple thing to detect. CREATE TABLE #UnusedIndexes (database_name sysname, table_name sysname, index_id int, object_id int, index_name sysname NULL, user_updates bigint, last_user_update datetime, user_seeks bigint, […]

Read More