JBoss.orgCommunity Documentation

Chapter 2. Results Caching

2.1. Support Summary
2.2. User Interaction
2.2.1. User Query Cache
2.2.2. Procedure Result Cache
2.3. Cached Virtual Procedure Definition
2.4. Cache Configuration
2.5. Cache Administration
2.6. Limitations

Teiid provides the capability to cache the results of specific user queries and virtual procedure calls.  This caching technique can yield significant performance gains if users of the system submit the same queries or execute the same procedures often.

User query result set caching will cache result sets based on an exact match of the incoming SQL string and PreparedStatement parameter values if present. Caching only applies to SELECT, set query, and stored procedure execution statements; it does not apply to SELECT INTO statements, or INSERT, UPDATE, or DELETE statements.

End users or client applications explicitly state whether to use result set caching.  This can be done by setting the JDBC ResultSetCacheMode execution property to true (default false) or by adding a cache hint to the query.   Note that if either of these mechanisms are used, Teiid must also have result set caching enabled (the default is enabled).

The most basic form of the cache hint, /*+ cache */, is sufficient to inform the engine that the results of the non-update command should be cached.


The pref_mem and ttl options of the cache hint may also be used for result set cache queries. If a cache hint is not specified, then the default time to live of the result set caching configuration will be used.


Note

Each query is re-checked for authorization using the current user’s permissions, regardless of whether or not the results have been cached.

To indicate that a virtual procedure (only definable by Teiid Designer) should be cached, it's definition should include a cache hint.


The pref_mem and ttl options of the cache hint may also be used for procedure caching.

Procedure results cache keys include the input parameter values. To prevent one procedure from filling the cache, at most 256 cache keys may be created per procedure per VDB.

A cached procedure will always produce all of its results prior to allowing those results to be consumed and placed in the cache. This differs from normal procedure execution which in some situations allows the returned results to be consumed in a streaming manner.

By default result set caching is enabled with 1024 maximum entries with a maximum entry age of 2 hours. There are actually 2 caches configured with these settings. One cache holds results that are specific to sessions and is local to each Teiid instance. The other cache holds VDB scoped results and can be replicated. See the <jboss-install>/server/<profile>/deploy/teiid/teiid-jboss-beans.xml config file or the Console's "Runtime Engine Properties" for tuning the configuration. The user may also override the default maximum entry age via the cache hint.

Result set caching is not limited to memory. There is no explicit limit on the size of the results that can be cached. Cached results are primarily stored in the BufferManager and are subject to it's configuration - including the restriction of maximum buffer space.

Note

While the result data is not held in memory, cache keys - including parameter values - may be held in memory. Thus the cache should not be given an unlimited maximum size.

Result set cache entries can be invalidated by data change events. The maxStaleness setting determines how long an entry will remain in the case after one of the tables that contributed to the results has been changed. See the Developers Guide for further customization.

The result set cache can be cleared through the AdminAPI using the clearCache method. The expected cache key is "QUERY_SERVICE_RESULT_SET_CACHE".


See the Admin Guide for more on using the AdminAPI and AdminShell.