I'm trying to analyse a query execution plan in my Oracle database. I have set
alter system set statistics_level = all;
Such that I can compare estimated cardinalities and times with actual cardinalities and times. Now, I'm running this statement in order to display that information.
select * from table(dbms_xplan.display_cursor(
sql_id => '6dt9vvx9gmd1x',
cursor_child_no => 2,
FORMAT => 'ALLSTATS LAST'));
But I keep getting this message
NOTE: cannot fetch plan for SQL_ID: 6dt9vvx9gmd1x, CHILD_NUMBER: 2
Please verify value of SQL_ID and CHILD_NUMBER;
It could also be that the plan is no longer in cursor cache (check
v$sql_plan)
The CHILD_NUMBER
was correct when the query was being executed. Also, when I run dbms_xplan.display_cursor
at the same time as the query, I get the actual plan. But my JDBC connection closes the PreparedStatement
immediately after execution, so maybe that's why the execution plan disappears from v$sql_plan
.
Am I getting something wrong, or how can I analyse estimated/actual values after execution?
The adaptive cursor sharing feature enables a single statement that contains bind variables to use multiple execution plans. Cursor sharing is "adaptive" because the cursor adapts its behavior so that the database does not always use the same plan for each execution or bind variable value.
The dbms_xplan. display_cursor is the function which was used in oracle, it was introduced in the oracle 10g version. This function is used to display the actual plan which was used by the query, it is not displaying the plantable for the execution plan.
V$SQL_PLAN contains the execution plan information for each child cursor loaded in the library cache.
You could always pin the cursor, which is new in 11g -
dbms_shared_pool.keep ('[address, hash_value from v$open_cursor]', 'C');
Increase the shared_pool to create more caching space for the cursors. If in 11g, capture the sql plan in the baselines using optimizer_capture_sql_plan_baselines. This stores the plans in dba_sql_plan_baselines.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With