How to delete stored execution plan?
Hello!
Version: 11.1.0.7.0
I need a function, which deletes a stored execution plan from the CBO by sql_id, to force a new hard-parse.
Background:
I have an application, which calles a lot of a select-statement (with bind), using a specific execution plan, lets say 'A'. This application will run and call in the next three days.
Now, I have recalculated the statistics of the table (by DBMS_STATS.GATHER_TABLE_STATS)
which is used for the query, to improve performance.
Now, the exexcution plan is good (say 'B'), and the query is fast, IF I copy the sql from the OEM to (any) other tool to get the execution plan...
But: The application still uses the plan 'A' (which still runs slow..).
(To opposite of the documentation! see Performance Tuning Guide, Chater 13.3.1 "When statistics are updated for a database object, Oracle invalidates any currently parsed SQL statements that access the object. The next time such a statement executes, the statement is re-parsed and the optimizer automatically chooses a new execution plan based on the new statistics.")
A short look into v$sql, v$sql_plan shows, that the application still uses the old sql_id, which has the wrong execution plan "A" stored.
The tested statements with plan B have the same sql, but other sql_id...