azure-sql-database - ALTER DATABASE SCOPED CONFIGURATION CLEAR PROCEDURE_CACHE 不删除缓存?
问题描述
我有一个 azure PaaS 数据库,想清除缓存以测试一些 SP。于是从网上找了一些脚本:
-- run this script against a user database, not master
-- count number of plans currently in cache
select count(*) from sys.dm_exec_cached_plans;
-- Executing this statement will clear the procedure cache in the current database, which means that all queries will have to recompile.
ALTER DATABASE SCOPED CONFIGURATION CLEAR PROCEDURE_CACHE;
-- count number of plans in cache now, after they were cleared from cache
select count(*) from sys.dm_exec_cached_plans;
-- list available plans
select * from sys.dm_exec_cached_plans;
select * from sys.dm_exec_procedure_stats
但是,缓存的数量始终在 600-800 左右,所以它并没有下降。
我没有收到任何错误(没有权限被拒绝等),那么这个命令如何不清理缓存?
解决方案
我还没有时间通过代码进行调试以确保 100% 确定,但根据我对系统的理解,很可能仅仅改变数据库模式版本(发生在任何 alter database 命令上)将使条目中的条目无效缓存下次使用。由于过程缓存是实例范围的,因此任何清除与数据库关联的条目的尝试都需要一个接一个地遍历所有条目,而不是仅仅释放整个缓存。
因此,您可以将其视为使整个缓存无效,但在重新编译或系统的其他部分通过以后的操作回收内存时懒惰地从缓存中删除条目。
Conor Cunningham 架构师,SQL
推荐阅读
- javascript - 如何使用 Cheerio 或 puppeteer 抓取所有 href?
- json - 在将 json 解码为 swift 模型类时出错
- javascript - 开玩笑测试。您如何测试来自同一模块的函数中的函数调用?
- wordpress - 使用高级自定义字段返回 null 的类别响应中的 Wordpress 类别图像
- c# - 跨所有应用程序实例的同步计时器
- javascript - 如何通过 Joi 检查值是对象还是对象数组
- python - 如何使用方法更改python中的实例变量?
- typescript - vscode.languages.registerCompletionItemProvider 不适用于“降价”
- scala - Scala 2.13.1 无法使用宏
- sabre - DailySalesReportLLSRQ 返回票务数据库错误