
V$SQL SHARED CURSOR - 日本エクセム株式会社 Oracle 技術情報
SQLチューニングのためには、そのSQLがどのように動いていて、データベースにどのように影響しているのか、を把握する必要があります。『MaxGauge』があれば簡単に状況が把握でき、適切なSQLチューニングができるようになります。
『MaxGauge』の資料はこちらから。
基本情報
概要
各Child CursorごとCursor共有が行われていない理由を提供するビューです。例えばBind Mismatchが生じた場合には、BIND_MISMATCHカラムの値がYに記録されます。
サポート
8i以上
カラム
名前 | タイプ | 説明 |
ADDRESS | RAW(4) | Address of the child cursor |
KGLHDPAR | RAW(4) | Address of the parent cursor |
UNBOUND_CURSOR | VARCHAR2(1) | N) The existing child cursor was not fully built (in other words, it was not optimized) |
SQL_TYPE_MISMATCH | VARCHAR2(1) | N) The SQL type does not match the existing child cursor |
OPTIMIZER_MISMATCH | VARCHAR2(1) | N) The optimizer environment does not match the existing child cursor |
OUTLINE_MISMATCH | VARCHAR2(1) | N) The outlines do not match the existing child cursor |
STATS_ROW_MISMATCH | VARCHAR2(1) | N) The existing statistics do not match the existing child cursor |
LITERAL_MISMATCH | VARCHAR2(1) | N) Non-data literal values do not match the existing child cursor |
SEC_DEPTH_MISMATC | VARCHAR2(1) | N) Security level does not match the existing child cursor |
EXPLAIN_PLAN_CURSOR | VARCHAR2(1) | N) The child cursor is an explain plan cursor and should not be shared |
BUFFERED_DML_MISMATCH | VARCHAR2(1) | N) Buffered DML does not match the existing child cursor |
PDML_ENV_MISMATCH | VARCHAR2(1) | N) PDML environment does not match the existing child cursor |
INST_DRTLD_MISMATCH | VARCHAR2(1) | N) Insert direct load does not match the existing child cursor |
SLAVE_QC_MISMATCH | VARCHAR2(1) | N) The existing child cursor is a slave cursor and the new one was issued by the coordinator (or, the existing child cursor was issued by the coordinator and the new one is a slave cursor) |
TYPECHECK_MISMATCH | VARCHAR2(1) | N) The existing child cursor is not fully optimized |
AUTH_CHECK_MISMATCH | VARCHAR2(1) | N) Authorization/translation check failed for the existing child cursor |
BIND_MISMATCH | VARCHAR2(1) | N) The bind metadata does not match the existing child cursor |
DESCRIBE_MISMATCH | VARCHAR2(1) | N) The typecheck heap is not present during the describe for the child cursor |
LANGUAGE_MISMATCH | VARCHAR2(1) | N) The language handle does not match the existing child cursor |
TRANSLATION_MISMATCH | VARCHAR2(1) | N) The base objects of the existing child cursor do not match |
ROW_LEVEL_SEC_MISMATCH | VARCHAR2(1) | N) The row level security policies do not match |
INSUFF_PRIVS | VARCHAR2(1) | N) Insufficient privileges on objects referenced by the existing child cursor |
INSUFF_PRIVS_REM | VARCHAR2(1) | N) Insufficient privileges on remote objects referenced by the existing child cursor |
REMOTE_TRANS_MISMATCH | VARCHAR2(1) | N) The remote base objects of the existing child cursor do not match |
LOGMINER_SESSION_MISMATCH | VARCHAR2(1) | N) |
INCOMP_LTRL_MISMATCH | VARCHAR2(1) | N) |
注意
High Version Count
SQL Textは同じですが、共有されていないChild Cursorの数は、V $ SQL_AREA.VERSION_COUNTカラムの値で知ることができます。この列の値が高い場合によくVersion Countが高くなります。高いVersion Countは、次のような問題と関連があります。
Version Countが高すぎる場合には、V$ SQL_SHARED_CURSORビューを利用してCursorが共有されていない理由を把握した後、問題を解決しなければなりません。
Cursorが共有されていない一般的な理由
例
Bind MismatchによるVersion Count増加
同じBind変数のためのさまざまな長さの値を使用すると、Bind Mismatchが発生することがあります。下の例を見て見ましょう。
オラクルは、Varchar型のBind変数の場合、その長さを次のように区間の値に切り上げています。
同じ区間の間に属するBind変数は、同じ長さで扱われるが、区間が異なる場合には、Bind Mismatchが発生します。V$ SQL_BIND_METADATAビューを使用すると、これを確認することができます。
上記のような現象を回避するには、同じサイズのBind変数を宣言する必要があります。
Java言語では、PreparedStatementを使用してBind変数を使用します。この場合にも、同じ問題が発生します。つまり、下の二つのPreparedStatementは、実際には共有ができません。
これらの現象は、ほとんどの場合、大きな問題にはなりません。しかし、単一のSQL文の数が多くのBind変数を使用して、各Bind変数ごとにBind Mismatchが発生した場合、その数は指数関数的に増えることになります。このような場合には、次のような方法を使用することができます。
上記のようにコードを変更すると、常に同じサイズの文字列が送信されるので、Bind Mismatchが発生しません。
関連情報
1. V$ SQL_BIND_METADATAビュー
外部参照
1. Library Cache Internals – Julian Dyke
SQLチューニングのためには、そのSQLがどのように動いていて、データベースにどのように影響しているのか、を把握する必要があります。『MaxGauge』があれば簡単に状況が把握でき、適切なSQLチューニングができるようになります。
『MaxGauge』の資料はこちらから。