How to Attach a SQL Profile to a Different Statement – Take 2
I posted on this topic a while back (How to Attach a SQL Profile to a Different Statement – Take 1), but wasn’t really happy with my solution. So here’s another shot at it. The basic idea is to be able to create a profile on one statement using hints or whatever other tricks you can come up with, and then attach the profile to a production statement on which you cannot modify the code. The basic steps of this technique are as follows:
- make a copy of the statement – (I use my build_bind_vars.sql (or build_bind_vars_awr.sql) script)
- do whatever you want to make it get the plan you want including adding hints
- create a Profile on the new statement – (I use my create_sql_profile.sql (rg_sqlprof1.sql) script)
- fix the Profile to eliminate any bad index hints – (I use my fix_sql_profile_hint.sql script)
- move the Profile over to the original statement – (I use my move_sql_profile.sql script)
The main reason I became dissatisfied with my previous approach was that it’s often necessary to fix one or more of the hints (see this post for the most common reason: Why Isn’t Oracle Using My Outline / Profile / Baseline?). The preceding steps allow the Profile to be tweaked before attaching it to the target statement. My previous approach created the profile and moved it all in one step. So there was no chance to modify the Profile before it was attached to the production statement. Anyways, here’s an example (note the examples are on a 10.2.0.4 database, but all the SQL should work on 11g as well):
Continue reading ‘How to Attach a SQL Profile to a Different Statement – Take 2’ »




