Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to delete stored execution plan?

Ulrich WeissOct 20 2009 — edited Oct 20 2009
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...
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 17 2009
Added on Oct 20 2009
2 comments
10,857 views