SQL Server 2000:如何知道存储过程已缓存了多少个计划?

发布于 2024-07-25 12:21:59 字数 121 浏览 3 评论 0原文

有时,在诊断 SQL Server 2000 数据库的问题时,了解存储过程正在使用错误的计划或在遇到问题时难以想出一个好的计划可能会有所帮助。 我想知道是否可以运行一个查询或命令来告诉我当前为特定存储过程缓存了多少个执行计划。

Sometimes when diagnosing issues with our SQL Server 2000 database it might be helpful to know that a stored procedure is using a bad plan or is having trouble coming up with a good plan at the time I'm running into problems. I'm wondering if there is a query or command I can run to tell me how many execution plans are cached currently for a particular stored procedure.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

溺ぐ爱和你が 2024-08-01 12:21:59

您可以通过多种不同的方式查询缓存,可以查看其内容,也可以查看一些相关的统计信息。

有几个命令可以帮助您:

SELECT * FROM syscacheobjects -- shows the contents of the procedure 
    -- cache for all databases
DBCC PROCCACHE -- shows some general cache statistics
DBCC CACHESTATS -- shows  the usage statistics for the cache, things like hit ratio

如果您只需要清除一个数据库的缓存,您可以使用:

DBCC FLUSHPROCINDB (@dbid) -- that's an int, not the name of it. 
           -- The int you'd get from sysdatabases or the dbid() function

编辑:上面的行是 2000,这就是问题所问的内容。 然而,对于任何使用SQL Server 2005的访问者来说,这与上面的安排略有不同:

select * from sys.dm_exec_cached_plans -- shows the basic cache stuff

用于显示 2005 年计划的有用查询:

SELECT  cacheobjtype, objtype, usecounts, refcounts, text
from sys.dm_exec_cached_plans p
join  sys.dm_exec_query_stats s on p.plan_handle = s.plan_handle
cross apply sys.dm_exec_sql_text(s.sql_handle)

You can query the cache in a number of different ways, either looking at its contents, or looking at some related statistics.

A couple of commands to help you along your way:

SELECT * FROM syscacheobjects -- shows the contents of the procedure 
    -- cache for all databases
DBCC PROCCACHE -- shows some general cache statistics
DBCC CACHESTATS -- shows  the usage statistics for the cache, things like hit ratio

If you need to clear the cache for just one database, you can use:

DBCC FLUSHPROCINDB (@dbid) -- that's an int, not the name of it. 
           -- The int you'd get from sysdatabases or the dbid() function

Edit: above the line is for 2000, which is what the question asked. However, for anyone visiting who's using SQL Server 2005, it's a slightly different arrangement to the above:

select * from sys.dm_exec_cached_plans -- shows the basic cache stuff

A useful query for showing plans in 2005:

SELECT  cacheobjtype, objtype, usecounts, refcounts, text
from sys.dm_exec_cached_plans p
join  sys.dm_exec_query_stats s on p.plan_handle = s.plan_handle
cross apply sys.dm_exec_sql_text(s.sql_handle)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文