<html>
<head>
    <base href="https://docs.jboss.org/author">
            <link rel="stylesheet" href="/author/s/en/2172/19/5/_/styles/combined.css?spaceKey=TEIID&amp;forWysiwyg=true" type="text/css">
    </head>
<body style="background: white;" bgcolor="white" class="email-body">
<div id="pageContent">
<div id="notificationFormat">
<div class="wiki-content">
<div class="email">
    <h2><a href="https://docs.jboss.org/author/display/TEIID/Hints+and+Options">Hints and Options</a></h2>
    <h4>Page <b>edited</b> by             <a href="https://docs.jboss.org/author/display/~shawkins">Steven Hawkins</a>
    </h4>
        <br/>
                         <h4>Changes (2)</h4>
                                 
    
<div id="page-diffs">
                    <table class="diff" cellpadding="0" cellspacing="0">
    
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >* _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. <br> <br></td></tr>
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">* _scope_\- if present overrides the computed scope for query results. 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.  Materialized views are always at a vdb scope. <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">* _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. <br></td></tr>
            <tr><td class="diff-unchanged" > <br></td></tr>
            <tr><td class="diff-unchanged" >h1. Limitations <br> <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
    
            </table>
    </div>                            <h4>Full Content</h4>
                    <div class="notificationGreySide">
        <h1><a name="HintsandOptions-CacheHint"></a>Cache Hint</h1>

<p>A query cache hint can be used to:</p>

<ul>
        <li>Indicate that a user query is eligible for result set caching and set the cache entry memory preference, time to live, etc.</li>
</ul>


<ul>
        <li>Set the materialized view memory preference, time to live, or updatablity.</li>
</ul>


<ul>
        <li>Indicate that a virtual procedure should be cachable and set the cache entry memory preference, time to live, etc.</li>
</ul>


<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: sql; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
/*+ cache[([pref_mem] [ttl:n] [updatable])] [scope:(session|user|vdb)] */ sql ...
</pre>
</div></div>

<ul>
        <li>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.</li>
</ul>


<ul>
        <li><em>pref_mem</em>&#45; if present indicates that the cached results should prefer to remain in memory.  The results may still be paged out based upon memory pressure.</li>
</ul>


<div class='panelMacro'><table class='noteMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/author/images/icons/emoticons/warning.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td>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.</td></tr></table></div>

<ul>
        <li><em>ttl:n</em>&#45; 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.</li>
</ul>


<ul>
        <li><em>updatable</em>&#45; 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.</li>
</ul>


<ul>
        <li><em>scope</em>&#45; 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.</li>
</ul>


<h1><a name="HintsandOptions-Limitations"></a>Limitations</h1>

<p>The form of the query hint must be matched exactly for the hint to have affect. For a user query if the hint is not specified correctly, e.g. <tt>/*&#43; cach(pref_mem) &#42;/</tt>, it will not be used by the engine nor will there be an informational log.  It is currently recommended that you verify (see Client Developers Guide) in your testing that the user command in the query plan has retained the proper hint.</p>

<h1><a name="HintsandOptions-OPTIONNOCACHE"></a>OPTION NOCACHE</h1>

<p>Individual queries may override the use of cached results by specifying <tt>OPTION NOCACHE</tt> 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.</p>

<div class="code panel" style="border-width: 1px;"><div class="codeHeader panelHeader" style="border-bottom-width: 1px;"><b>Full NOCACHE</b></div><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: java; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
SELECT * from vg1, vg2, vg3 WHERE … OPTION NOCACHE
</pre>
</div></div>

<p>No cached results will be used at all.</p>

<div class="code panel" style="border-width: 1px;"><div class="codeHeader panelHeader" style="border-bottom-width: 1px;"><b>Specific NOCACHE</b></div><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: java; gutter: false" style="font-size:12px; font-family: ConfluenceInstalledFont,monospace;">
SELECT * from vg1, vg2, vg3 WHERE … OPTION NOCACHE vg1, vg3
</pre>
</div></div>

<p>Only the vg1 and vg3 caches will be skipped, vg2 or any cached results nested under vg1 and vg3 will be used.</p>

<p><tt>OPTION NOCACHE</tt> may be specified in procedure or view definitions.  In that way, transformations can specify to always use real-time data obtained directly from sources.</p>
    </div>
        <div id="commentsSection" class="wiki-content pageSection">
        <div style="float: right;" class="grey">
                        <a href="https://docs.jboss.org/author/users/removespacenotification.action?spaceKey=TEIID">Stop watching space</a>
            <span style="padding: 0px 5px;">|</span>
                <a href="https://docs.jboss.org/author/users/editmyemailsettings.action">Change email notification preferences</a>
</div>
        <a href="https://docs.jboss.org/author/display/TEIID/Hints+and+Options">View Online</a>
        |
        <a href="https://docs.jboss.org/author/pages/diffpagesbyversion.action?pageId=18646108&revisedVersion=7&originalVersion=6">View Changes</a>
                |
        <a href="https://docs.jboss.org/author/display/TEIID/Hints+and+Options?showComments=true&amp;showCommentArea=true#addcomment">Add Comment</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>