执行select语句后是否有可能清除缓存?
我试着用我的一个sql,第一次执行它,它返回3.15分钟,第二次(dint更改任何东西)它返回2.55分钟。
对我来说测试sql上的实际性能有点乏味。
我发现在this帖子上的Sql Server 2005上有缓存。
我对sql server 2008上的缓存是否正确?
答案 0 :(得分:1)
这就是我为同一目的所做的事情:
DBCC FREEPROCCACHE DBCC DROPCLEANBUFFERS GO DROP TABLE [WHATEVER I NEED TO DROP] GO TRUNCATE TABLE [WHATEVER I NEED TO EMPTY] GO UPDATE [WHATEVER HAS TO BE "RESET"] GO [DO REST OF "RESET ACTIONS" HERE] USE [YOUR DATABASE NAME] GO
DECLARE @start_time datetime, @end_time datetime, @miliseconds int
DECLARE @ALL_YOUR_VARS -- _YOU'LL_USE_WHILE_YOU_MEASURE /* BECAUSE YOU DON'T WANT TO MEASURE THE TIME SPENT ON TEMP VARS YOU CREATE FOR MEASURING EXEC TIME ONLY */
-- TODO: SET VARS' VALUES HERE, SAME REASON AS ABOVE
SET @start_time = GETDATE()
-- [EXECUTE ALL YOUR STATEMENTS HERE] -- [YOU WANT TO MEASURE]
SET @end_time = GETDATE() SET @miliseconds = DATEDIFF(ms, @start_time, @end_time) SELECT @start_time, @end_time, CAST(@miliseconds AS VARCHAR(max)) + ' ms' GO
USE master GO
SET NOCOUNT ON DECLARE @DBName varchar(50) DECLARE @spidstr varchar(8000) DECLARE @ConnKilled smallint SET @ConnKilled=0 SET @spidstr = ''
Set @DBName = 'YOURDBNAMEHERE' IF db_id(@DBName) < 4 BEGIN PRINT 'Connections to system databases cannot be killed' RETURN END SELECT @spidstr=coalesce(@spidstr,',' )+'kill '+convert(varchar, spid)+ '; ' FROM master..sysprocesses WHERE dbid=db_id(@DBName)
IF LEN(@spidstr) > 0 BEGIN EXEC(@spidstr) SELECT @ConnKilled = COUNT(1) FROM master..sysprocesses WHERE dbid=db_id(@DBName) END