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!

Poor Execution Plan - How to Force Use of Correct Plan?

jimdSep 13 2012 — edited Sep 14 2012
I've got a query running from 3rd party product that is executing slowly - the cause it is clear as explain plan shows inefficient access including a scan of a whole partition rather than using an index that is specifically for that purpose.
This behaviour is reproducible when the query runs interactively from SQLPlus i.e. same poor explain plan used.

By making a small change to the query (that should not affect the optimiser) leads the query generatng a good explain plan, i.e. uses the index, and the query runs very quickly.
"small change" is something as slight as giving a column a different alias in the SELECT, or changing the "COUNT(1)" to "COUNT(*).
Similarly a hint in the query results in an efficient performant plan.

The DB is 11.2.0.2 Enterprise running on Linux.


So my questions are:
+*What is happening here?*+
+*What can I do to get the origional query to choose the correct plan?*+

- I do not have access to the code, and so chaning the query (e.g. including a hint) is not an option.

- I could use SQL Profile to influence the plan that is selected, but the problem is that the generation of the query is dynamic based on user input, and so it would not be feasible to profile all possible variations.

- I believe that when the poorly performing query was 1st executed there may have been missing/stale statistics. These are now all up to date. (This was before I was involved).
Could it be the case that the reason the poor execution plan is that because it was 1st parsed when staistics were missing, and even through statistics now available the plan is cached and being re-used? I thought that when statistics where generated then cached queries referenced would be flushed out? If this is the case then how can I flush this query out so that it is re-parsed and hopefully generate the good plan?


I recognise that details of query etc are missing, but I'm looking here for a steer to how to progress with resolving this type of problem rather than an exact answer to a specfic query (as is the case in many threads). However if more details required then no problem - I can post query, plans, statistics, autotrace or whatever needed up to help.

thanks in anticipation...........
This post has been answered by Iordan Iotzov on Sep 13 2012
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 12 2012
Added on Sep 13 2012
12 comments
1,605 views