nic*_*key 4 sql-server stored-procedures
我有一个存储过程,它为业务仪表板返回大量数据。第一次加载需要 18 秒,之后需要 0 秒,即使我随机更改输入参数,它也会保持在 0 秒并返回正确的结果。
如果我等了大约三分钟,它会回到 18 秒。这对用户来说是不可接受的,我已经用尽了我知道的每一个选项。
为什么在第一次加载时会很慢,但之后会很快?我知道它可能正在重新编译执行计划,因此在我添加的每个查询中都添加了 OPTION (KEEP PLAN);没有效果。我的存储过程没有'with recompile'。我下载了“datawizard sql profiler”并设置了一个跟踪以显示重新编译,但它没有显示任何内容,即使我在查询中使用了“with recompile”。
我唯一的其他想法是 mssql 正在执行某种结果缓存,但即使我更改参数,查询也运行得很快。
为什么我等了一会儿又需要 18 秒,然后是 0,然后又是 18 秒?
问题是在服务器上的一系列数据库上将“自动关闭”设置设置为 true。即使数据库无关,它们的“自动关闭”设置也会刷新服务器上的所有执行计划。
以下是您将在 auto_close 设置为 true 时看到的日志问题类型:
SQL Server has encountered 24 occurrence(s) of cachestore flush for the 'Object Plans' cachestore (part of plan cache) due to some database maintenance or reconfigure operations.
SQL Server has encountered 24 occurrence(s) of cachestore flush for the 'SQL Plans' cachestore (part of plan cache) due to some database maintenance or reconfigure operations.
SQL Server has encountered 24 occurrence(s) of cachestore flush for the 'Bound Trees' cachestore (part of plan cache) due to some database maintenance or reconfigure operations.
Run Code Online (Sandbox Code Playgroud)
正如您在本文中看到的,永远不要将自动关闭设置为真!!!http://sqlmag.com/blog/worst-practice-allowing-autoclose-sql-server-databases
| 归档时间: |
|
| 查看次数: |
3357 次 |
| 最近记录: |