クエリ・キャッシュ・ヒントは次のように使用できます:

  • Userクエリが結果セットキャッシュの対象であることを示し、キャッシュエントリメモリの優先順位や有効時間などを設定します;

  • キャッシュされたビューメモリの環境設定、TIME、更新可能性を設定します;

  • 仮想プロシージャがキャッシュ可能であることを指示し、キャッシュ・エントリの優先メモリや有効時間などを設定します:

    /*+ cache[([pref_mem] [ttl:n] [updatable] [scope:session|user|vdb])]*/ sql ...

  • Cache HintはSQLの先頭に表示されます。これは、先頭のコメントのいずれかとして表示することができ、INSERT / UPDATE / DELETEステートメントまたはINSTEAD OF TRIGGERSには影響しません。

角括弧内のパラメータはオプションで、存在する場合は以下の意味になります:

Parameter

Description

pref_mem

Indicates that the cached results should preferably remain in memory. The results may still be paged out based upon memory pressure.
Please be careful 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 behaviour

ttl: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 cached views

updatable

Indicates that the cached results can be updated. Defaults to FALSE for cached 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 presence of the scope overrides the computed scope. Cached views, on the other hand, default to the vdb scope. For cached views, explicitly setting the session or user scopes will result in a non-replicated session scoped cached view

Example

この例では、キャッシュされたクエリの結果は、好ましくは1分間メモリに保存されます:

/*+ cache(pref_mem ttl:60000) */ SELECT COUNT(*) FROM (CALL "s3_no_path1.listFiles"(
"pathAndPattern" => '/xxx/*'
)) AS a ;;

Limitations

ヒントを有効にするには、クエリヒントの書式が正確にマッチしている必要があります。ユーザー ク エ リ の場合、 ヒ ン ト が正 し く 指定 さ れていない場合 (/*+ cach(pref_mem) */など)、 ヒ ン ト はエン ジ ン で使用 さ れず、 ロ グに も 情報が残 り ません。

OPTION NOCACHE

個々のクエリでOPTION NOCACHEを指定することで、キャッシュ結果の使用を上書きすることができます。0個以上の完全修飾されたビュー名またはプロシージャ名を指定して、キャッシュされた結果を使用しないようにすることができます。名前が指定されない場合、キャッシュされた結果は推移的に使用されません。

Full NOCACHE

この場合、結果は全く使用されません:

SELECT * from vg1, vg2, vg3 WHERE … OPTION NOCACHE

Specific NOCACHE

この例では、vg1vg3のキャッシュのみがスキップされ、vg2またはvg1vg3の下にネストされたキャッシュ結果が使用されます:

SELECT * from vg1, vg2, vg3 WHERE … OPTION NOCACHE vg1, vg3

OPTION NOCACHEをプロシージャ定義やビュー定義で指定することができます。このようにして、変換は常にソースから直接取得したリアルタイムのデータを使用するように指定することができます。