SQL Server CACHES 是否查询结果?

Does SQL Server CACHES Query Results?(SQL Server CACHES 是否查询结果?)
本文介绍了SQL Server CACHES 是否查询结果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我运行查询时,SQL Server 会缓存结果吗?

When I run a query does the SQL Server caches the results?

因为:当我运行以下查询时:

Because: When I run the below query:

SELECT id
FROM Foo
WHERE Foo.Name LIKE '%bar%'

查询第一次运行 40 秒.

但在第二次运行时,只需要几秒钟.

这是因为以某种方式缓存了执行计划,还是实际上缓存了数据,以便我可以在第二次运行时更快地检索它?

Is this because the execution plan is somehow cached or actually the data is cached so that I can retrieve it much faster on the 2nd run?

推荐答案

SQL Server 不会缓存查询结果,但会缓存 数据页 它在内存中读取.然后将这些页面中的数据用于生成查询结果.

SQL Server does not cache the query results, but it caches the data pages it reads in memory. The data from these pages is then used to produce the query result.

您可以通过设置轻松查看数据是从内存中读取的还是从磁盘中读取的

You can easily see if the data was read from memory or from disk by setting

SET STATISTICS IO ON

返回以下有关执行查询的信息

Which returns the following information on execution of the query

Table 'ProductCostHistory'. Scan count 1, logical reads 5, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.

逻辑读取和物理读取的区别在于从内存中读取的数据.

The difference between logical and physical reads is the data read from memory.

SQL Server 还将要求内存用于缓存,直到达到最大值(配置或物理最大值),然后刷新最近最少使用的页面.

SQL Server will also claim Memory for caching until the maximum (configured, or physical maximum) is reached and then the least recently used pages are flushed.

这篇关于SQL Server CACHES 是否查询结果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

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

相关文档推荐

Execute complex raw SQL query in EF6(在EF6中执行复杂的原始SQL查询)
Hibernate reactive No Vert.x context active in aws rds(AWS RDS中的休眠反应性非Vert.x上下文处于活动状态)
Bulk insert with mysql2 and NodeJs throws 500(使用mysql2和NodeJS的大容量插入抛出500)
Flask + PyMySQL giving error no attribute #39;settimeout#39;(FlASK+PyMySQL给出错误,没有属性#39;setTimeout#39;)
auto_increment column for a group of rows?(一组行的AUTO_INCREMENT列?)
Sort by ID DESC(按ID代码排序)