如何清除 SQL Server 查询缓存?

How can I clear the SQL Server query cache?(如何清除 SQL Server 查询缓存?)
本文介绍了如何清除 SQL Server 查询缓存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个针对 SQL Server 2005 运行的简单查询

I've got a simple query running against SQL Server 2005

SELECT * 
FROM Table 
WHERE Col = 'someval'

第一次执行查询可以取>15 秒.后续执行返回 <1 秒.

The first time I execute the query can take > 15 secs. Subsequent executes are back in < 1 sec.

如何让 SQL Server 2005 不使用任何缓存结果?我试过跑步

How can I get SQL Server 2005 not to use any cached results? I've tried running

DBCC DROPCLEANBUFFERS
DBCC FREEPROCCACHE

但这似乎对查询速度没有影响(仍然是<1 sec).

But this seems to have no effect on the query speed (still < 1 sec).

推荐答案

这里有一些很好的解释.看看吧.

Here is some good explaination. check out it.

http://www.mssqltips.com/tip.asp?tip=1360

CHECKPOINT; 
GO 
DBCC DROPCLEANBUFFERS; 
GO

来自链接的文章:

如果所有性能测试都在 SQL Server 中进行,最好的方法可能是发出 CHECKPOINT,然后发出 DBCC DROPCLEANBUFFERS 命令.尽管 CHECKPOINT 进程是 SQL Server 中的一个自动内部系统进程并且定期发生,但发出此命令以将当前数据库的所有脏页写入磁盘并清理缓冲区非常重要.然后可以执行 DBCC DROPCLEANBUFFERS 命令从缓冲池中删除所有缓冲区.

If all of the performance testing is conducted in SQL Server the best approach may be to issue a CHECKPOINT and then issue the DBCC DROPCLEANBUFFERS command. Although the CHECKPOINT process is an automatic internal system process in SQL Server and occurs on a regular basis, it is important to issue this command to write all of the dirty pages for the current database to disk and clean the buffers. Then the DBCC DROPCLEANBUFFERS command can be executed to remove all buffers from the buffer pool.

这篇关于如何清除 SQL Server 查询缓存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Execute complex raw SQL query in EF6(在EF6中执行复杂的原始SQL查询)
SSIS: Model design issue causing duplications - can two fact tables be connected?(SSIS:模型设计问题导致重复-两个事实表可以连接吗?)
SQL Server Graph Database - shortest path using multiple edge types(SQL Server图形数据库-使用多种边类型的最短路径)
Invalid column name when using EF Core filtered includes(使用EF核心过滤包括时无效的列名)
How should make faster SQL Server filtering procedure with many parameters(如何让多参数的SQL Server过滤程序更快)
How can I generate an entity–relationship (ER) diagram of a database using Microsoft SQL Server Management Studio?(如何使用Microsoft SQL Server Management Studio生成数据库的实体关系(ER)图?)