簡體   English   中英

SQL Server 2000:如何確定一個存儲過程已緩存了多少個計划?

[英]SQL Server 2000: How can I tell how many plans a stored procedure has cached?

有時,當診斷我們的SQL Server 2000數據庫問題時,了解存儲過程正在使用錯誤的計划或在遇到問題時無法制定良好的計划可能會有所幫助。 我想知道是否可以運行查詢或命令來告訴我當前為特定存儲過程緩存了多少執行計划。

您可以通過多種不同的方式查詢緩存,既可以查看其內容,也可以查看一些相關的統計信息。

幾個命令可以幫助您:

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)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM