Skip to Main Content

Breadcrumb

Question and Answer

Connor McDonald

Thanks for the question, Satender.

Asked: August 23, 2016 - 5:08 am UTC

Last updated: July 24, 2017 - 1:38 am UTC

Version: 11.2.0.3.0

Viewed 50K+ times! This question is

You Asked

Hi Tom,

I have SQL HC for a SQL ID which shows the query have two Hash Plans one is Optimal and another which elapse a lot. And my query is taking long time to run which means that it is using the worst plan.
I want to force my query to use the Optimal plan.

Please suggest how to force a SQL ID to use any specific Hash Plan only.

Thanks and Regards
Satender

and Connor said...

Take a look at this magazine article

http://www.oracle.com/technetwork/issue-archive/2014/14-jul/o44asktom-2196080.html

It shows step by step how to use a sql plan baseline to lock down the plan to the one you want.

Rating

  (3 ratings)

Is this answer out of date? If it is, please let us know via a Comment

Comments

Question Solved but another question is there

Satender Dalal, August 24, 2016 - 11:19 am UTC

Hi Tom,

I have gone through the document which you have provided. That was useful.
There if you see one Plan was Disabled.
So if i drop the disabled plan, will that also be the same thing.
In my case i have 2 plans already, so i have a option to load only one hash plan in Base line
So can i go with loading only one plan.
Connor McDonald
August 25, 2016 - 3:14 am UTC

Yes, if you have both plans loaded into the baseline, then all you need to do is disable the bad one. The other one will be the one that the optimizer then uses.

Execution hash value of one sql_id to another sql_id?

Dana, July 20, 2017 - 10:00 pm UTC

I have a scenario where tables are highly volatile, and suffer from rather frequent changes in execution times.

Most are in the form of:
insert into table t (list_of_columns) (select [list_of_columns] from table y where id=:b1);

When I can pre-set/pre-run stats, and run a similar query with a literal value like:
insert into table t (list_of_columns) (select [list_of_columns] from table y where id=999);

I get a execution time measured in seconds.

With bind variables, and stats not up to date, execution times range from minutes to days.

I have captured both good baseline and not so good baselines using DBMS_SPM. Since I used literal values in the second query, it has a different SQL_ID from the first query.
SQL_HANDLE is also different.

My question is this. Is there a way to transfer the execution plan from the good baseline to the not so good baseline?

Thank you for your time.

Connor McDonald
July 24, 2017 - 1:38 am UTC

There is a nice walkthough of the steps in Nigel Bayliss (Optimizer Product Manager) white paper on how do this.

http://www.oracle.com/technetwork/database/bi-datawarehousing/twp-sql-plan-mgmt-12c-1963237.pdf

It starts on page 18, in a nutshell

- load plan for bad sql
- set it to disabled
- load plan for a hinted sql (hinted to make it run as you want)
- match the good plan with the bad sql's "handle"

Forgot version ...

Dana, July 20, 2017 - 10:14 pm UTC

My prior review/follow up is for AIX Oracle version 12.1.0.2.0.

Sorry for the omission.

More to Explore

Performance

Get all the information about database performance in the Database Performance guide.