搜索

此内容没有您所选择的语言版本。

3.8. Cache Hints and Options

download PDF
A query cache hint can be used in the following ways:
  • Indicate that a user query is eligible for result set caching and set the cache entry memory preference, time to live and so forth.
  • Set the materialized view memory preference, time to live, or updatablity.
  • Indicate that a virtual procedure should be cachable and set the cache entry memory preference, time to live and so on
      
        	 /*+ cache[([pref_mem] [ttl:n] [updatable])] [scope:(session|user|vdb)] */ sql ...
        	 
  • The cache hint should appear at the beginning of the SQL. It will not have any affect on INSERT/UPDATE/DELETE statements or INSTEAD OF TRIGGERS.
  • pref_mem- if present indicates that the cached results should prefer to remain in memory. The results may still be paged out based upon memory pressure.

    Important

    Care should be taken to not over use the pref_mem option. The memory preference is implemented with Java soft references. While soft references are effective at preventing out of memory conditions. Too much memory held by soft references can limit the effective working memory. Consult your JVM options for clearing soft references if you need to tune their behavior.
  • ttl:n- if present n indicates the time to live value in milliseconds. The default value for result set caching is the default expiration for the corresponding Infinispan cache. There is no default time to live for materialized views.
  • updatable- if present indicates that the cached results can be updated. This defaults to false for materialized views and to true for result set cache entries.
  • scope- There are three different cache scopes: session - cached only for current session, user - cached for any session by the current user, vdb - cached for any user connected to the same vdb. For cached queries the presense of the scope overrides the computed scope. Materialized views on the other hand default to the vdb scope. For materialized views explicitly setting the session or user scopes will result in a non-replicated session scoped materialized view.
The pref_mem, ttl, updatable, and scope values for a materialized view may also be set via extension properties on the view (by using the teiid_rel namespace with MATVIEW_PREFER_MEMORY, MATVIEW_TTL, MATVIEW_UPDATABLE, and MATVIEW_SCOPE respectively). If both are present, the use of an extension property supersedes the usage of the cache hint.

Note

The form of the query hint must be matched exactly for the hint to be effective. For a user query if the hint is not specified correctly, e.g. /*+ cach(pref_mem) */, it will not be used by the engine nor will there be an informational log. It is currently recommended that you verify in your testing that the user command in the query plan has retained the proper hint.
Individual queries may override the use of cached results by specifying OPTION NOCACHE on the query. 0 or more fully qualified view or procedure names may be specified to exclude using their cached results. If no names are specified, cached results will not be used transitively. In this case, no cached results will be used at all:
  
   SELECT * from vg1, vg2, vg3 WHERE … OPTION NOCACHE
   
In this case, only the vg1 and vg3 caches will be skipped. vg2 or any cached results nested under vg1 and vg3 will be used:
  
   SELECT * from vg1, vg2, vg3 WHERE … OPTION NOCACHE vg1, vg3
   
OPTION NOCACHE may be specified in procedure or view definitions. In that way, transformations can specify to always use real-time data obtained directly from sources.
Red Hat logoGithubRedditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

© 2024 Red Hat, Inc.