sql_handle and plan_handle (读书笔记)

The sys.dm_exec_cached_plan dmv contains a column called a plan_handle for every compiled plan. The plan_handle is a hashed value that derives from compiled plan of entire batch, and it is guaranteed to be unique for every currently exist compiled plan. The plan_handle can be used as an identifier for a compiled plan

 

The actual SQL Test of a batch or objects is stored in another cache called the SQL Manager Cache(SQLMGR). The sql test associated with each batch is stored in its entirety, including all the comments. And it's can be retrieved using a data value called sql_handle. The sql_handle contains a hash of the entire batch text , and because it is unique for every batch, the sql_handle can serve as a identifier for the batch text in the SQLMGR cache .

 

For specific sql test, it always has the same sql_handle, but it may not always have the same plan_handle. If the cache keys change, we'll get a new plan_handle in plan cache. The relationship between sql_handle and plan_handle is thus 1:N

 

The following example indicates that one sql_handle maps two plan_handle because the SET option changed.

dbcc freeproccache

go

SET CONCAT_NULL_YIELDS_NULL off

go

select top 1 null+'aa' from sys.objects

go

SET CONCAT_NULL_YIELDS_NULL on

go

select top 1 null+'aa' from sys.objects

go

select COUNT(plan_handle),sql_handle from sys.dm_exec_query_stats group by sql_handle

go

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值