0

是否有任何 DBMS(Oracle、MySQL、SQLite、PostGres)提供结果集的缓存?我试图了解缓存 SQL 结果以减少数据库负载的最常用方法是什么。我的理解是,数据库是扩展应用程序的瓶颈,而缓存将有助于减少数据库的负载。

如果 DBMS 不提供结果缓存,那么使用 Memcache 等缓存工具是否是个好主意?

4

2 回答 2

3

数据库通常缓存查询的执行计划,而不是结果集本身。

一种可行的方法当然是执行您的建议并为此使用 Memcache。Memcache 只是提供此类功能的众多工具之一。该决定很大程度上取决于您正在使用的环境、应用程序的类型(Web 与 Windows)、架构等。

例如,如果结果集不是太大,您可能会将其缓存在内存中。

于 2012-07-17T05:25:06.910 回答
1

Oracle offers several ways to achieve a cache. It depends on which version of the Oracle database you are using. In older versions you could opt to "pin a table in memory". This effectively cached any frequently accessed table into cache. Care needs to be taken here in that this could be used a little too liberally. There is also the option of using Materialized Views. Now, this is not a method of caching but the benefits along the same lines as caching. Oracle 11g now allows the caching of queries at both database and session level. This is achieved through the use of hints. Look for RESULT_CACHE_MODE and RESULT_CACHE. There are various configuration settings and EXPLAIN PLAN can display whether a query is being read from RESULT CACHE. I don't have experience of third party tools such as Memcache(?) but the danger of using tools such as this - is you may actually circumvent anything (something of benefit) Oracle implements into their own RDBMS.

于 2012-07-18T10:16:31.437 回答