Tell oracle which plan is optimal?

It's easy enough in 10g to get a query's history of execution plans and execution statistics, and so it's often easy to tell the bad plan from the good plan especially when user complaints coincide with the plan that uses many more gets per execution. I can see the sql_id, I can see the plan_hash_value for the efficient plan, why can't I just run a function that says "associate this plan with this sql_id always until I tell you otherwise?" Yes, I know there might be more than one optimal plan for some queries, but I have seen plenty of cases where there's one obviously better plan for all inputs - when plan B is used there are no complaints of slowness, when plan C is used users call the help desk. All I need is to get oracle to understand that sql_id A works best with plan B.
Maybe something like:
dbms_stats.create_profile_from_existing_plan(sql_id=> x, plan_hash_value => y );
would get the details from dba_hist*.
This can't be that difficult to implement, can it? Why isn't it provided/supported? How hard would it be to implement using calls to oracle functions?
Thanks.

user447327 wrote:
Thanks, I'm familiar with outlines, in that I don't want to try to record one while trying to get just the right combination of sql text and statistics and inputs to get the plan I want. In this case, the optimizer has already found the good plan, but it doesn't always stick to the good plan. I could change statistics gathering techniquex, but I want a local fix. I'm familiar with the sql tuning advisor, but it never gives me good advice. I can rewrite sql, but not for applications that won't allow me to change the source code.
If I could get that information for a good plan for a particular sql_id/plan_hash_value from v$sql* maybe I could transform a plan into an outline.
So, I'm asking why this apparently simple feature isn't available, not for advice on how to use more complicated existing features. Which is not to say that I don't appreciate your posting that interesting URL. I think maybe I am just lazier ( in a good way, I hope ) than you are.
The answer to my sporadic performance problem is sitting right in front of me. The optimizer has already produced the correct result, along with one or more wrong results. The right answer doesn't need to be recalculated or recosted or reparsed - it's a previously-solved problem. I want Oracle to remember the solution when I tell it that sql_id A and plan_hash_value B should always be together. The information that is already available needs to be addressible in minimal terms ( sql_id, plan_hash_value ) in such a way that the desired plan is always associated with the problem query.
This would be useful in cases where there isn't more than one optimal plan.
dbms_no_cbo.marry(sql_id=> x, plan_hash_value=>y);Apologies, but I saw your post only now. The desperately sought functionality is already there in 10g using Stored Outlines. Note that the CREATE_OUTLINE procedure has been added in 10g, it wasn't available in pre-10g versions.
CREATE_OUTLINE Procedure
This procedure generates an outline from the shared cursor identified by hash value and child number.
DBMS_OUTLN.CREATE_OUTLINE (
   hash_value    IN NUMBER,
   child_number  IN NUMBER,
   category      IN VARCHAR2 DEFAULT 'DEFAULT');Of course, SPM in 11g supersedes this, but this should do what you're looking for in 10g.
Another, slightly more cumbersome approach, would be creating a SQL profile using two undocumented functions/options but it allows to refer to the plans stored in the AWR which is not possible using above approach.
The interesting feature of SQL profiles is that these allow to match SQL similar to the CURSOR_SHARING functionality, i.e. replaces literals with bind variables before attempting to match the SQL text. See the FORCE_MATCH parameter below.
Step 1: Get the outline information from the shared pool or the AWR
Note that the OUTLINE option is undocumented. You could also use the ADVANCED option (undocumented, too, but look here: http://jonathanlewis.wordpress.com/2008/03/06/dbms_xplan3/):
Shared Pool:
SELECT * FROM TABLE(DBMS_XPLAN.DISPLAY_CURSOR('<sql_id>', <child_number>, 'OUTLINE');AWR:
SELECT * FROM TABLE(DBMS_XPLAN.DISPLAY_AWR('<sql_id>', <child_number>, null, 'OUTLINE');This generates the execution plan along with the OUTLINE information which looks e.g. like that:
  /*+                                                                                               
      BEGIN_OUTLINE_DATA                                                                            
      IGNORE_OPTIM_EMBEDDED_HINTS                                                                   
      OPTIMIZER_FEATURES_ENABLE('10.2.0.3')                                                         
      OPT_PARAM('query_rewrite_enabled' 'false')                                                    
      OUTLINE_LEAF(@"SEL$2")                                                                        
      OUTLINE_LEAF(@"SEL$1")                                                                        
      INDEX(@"SEL$1" "I"@"SEL$1" "I_OBJ#")                                                          
      INDEX_RS_ASC(@"SEL$1" "IST"@"SEL$1" ("IND_STATS$"."OBJ#"))                                    
      NO_ACCESS(@"SEL$1" "C"@"SEL$1")                                                               
      LEADING(@"SEL$1" "I"@"SEL$1" "IST"@"SEL$1" "C"@"SEL$1")                                       
      USE_NL(@"SEL$1" "IST"@"SEL$1")                                                                
      USE_HASH(@"SEL$1" "C"@"SEL$1")                                                                
      INDEX_RS_ASC(@"SEL$2" "CDEF$"@"SEL$2" ("CDEF$"."OBJ#"))                                       
      END_OUTLINE_DATA                                                                              
  */                                                                                                 Step 2:
Generate an SQL profile using above OUTLINE information. Note that the IMPORT_SQL_PROFILE procedure is undocumented.
begin
dbms_sqltune.import_sql_profile(
  sql_text    => '<the_full_sql_text>'
, profile     => sqlprof_attr('<hint1>','<hint2>')
, name        => 'PROFILE_name'
  -- use force_match => true
  -- to use CURSOR_SHARING=SIMILAR
  -- behaviour, i.e. match even with
  -- differing literals
, force_match => false
end;
/A code snippet how this could be combined into an automated SQL*Plus script, parameter is the SQL_ID:
declare
  ar_hint_table    sys.dbms_debug_vc2coll;
  ar_profile_hints sys.sqlprof_attr := sys.sqlprof_attr();
  cl_sql_text      clob;
  i                pls_integer;
begin
  with a as (
  select
           rownum as r_no
         , a.*
  from
           table(
             -- replace with
             -- DBMS_XPLAN.DISPLAY_AWR
             -- if required
             dbms_xplan.display_cursor(
               '&&1'
             ,  null
             , 'OUTLINE'
             -- dbms_xplan.display_awr(
             --   '&&1'
             -- , null
             -- , null
             -- , 'OUTLINE'
           ) a
  b as (
  select
           min(r_no) as start_r_no
  from
           a
  where
           a.plan_table_output = 'Outline Data'
  c as (
  select
           min(r_no) as end_r_no
  from
           a
         , b
  where
           a.r_no > b.start_r_no
  and      a.plan_table_output = '  */'
  d as (
  select
           instr(a.plan_table_output, 'BEGIN_OUTLINE_DATA') as start_col
  from
           a
         , b
  where
           r_no = b.start_r_no + 4
  select
           substr(a.plan_table_output, d.start_col) as outline_hints
  bulk collect
  into
           ar_hint_table
  from
           a
         , b
         , c
         , d
  where
           a.r_no >= b.start_r_no + 4
  and      a.r_no <= c.end_r_no - 1
  order by
           a.r_no;
  select
           sql_text
  into
           cl_sql_text
  from
           -- replace with dba_hist_sqltext
           -- if required for AWR based
           -- execution
           v$sql
           -- sys.dba_hist_sqltext
  where
           sql_id = '&&1';
  -- this is only required
  -- to concatenate hints
  -- splitted across several lines
  -- and could be done in SQL, too
  i := ar_hint_table.first;
  while i is not null
  loop
    if ar_hint_table.exists(i + 1) then
      if substr(ar_hint_table(i + 1), 1, 1) = ' ' then
        ar_hint_table(i) := ar_hint_table(i) || trim(ar_hint_table(i + 1));
        ar_hint_table.delete(i + 1);
      end if;
    end if;
    i := ar_hint_table.next(i);
  end loop;
  i := ar_hint_table.first;
  while i is not null
  loop
    ar_profile_hints.extend;
    ar_profile_hints(ar_profile_hints.count) := ar_hint_table(i);
    i := ar_hint_table.next(i);
  end loop;
  dbms_sqltune.import_sql_profile(
    sql_text    => cl_sql_text
  , profile     => ar_profile_hints
  , name        => 'PROFILE_&&1'
  -- use force_match => true
  -- to use CURSOR_SHARING=SIMILAR
  -- behaviour, i.e. match even with
  -- differing literals
  , force_match => false
end;
/Regards,
Randolf
Oracle related stuff blog:
http://oracle-randolf.blogspot.com/
SQLTools++ for Oracle (Open source Oracle GUI for Windows):
http://www.sqltools-plusplus.org:7676/
http://sourceforge.net/projects/sqlt-pp/
Edited by: Randolf Geist on Mar 26, 2009 10:00 PM
Added automated SQL profile generation

Similar Messages

  • Could you please tell me, which oracle commands can get below result?

    Could you please tell me, which oracle commands can get below result?
    1. Total size of archive generated
    TotalArchive (GB) Date
    24.415 28-02-2013
    14.223 29-03-2013
    12.133 30-02-2013
    2. Total number of archive logs generated
    COUNT(SEQUENCE#) TO_CHAR
    123 28-03-13
    234 29-03-13
    124 30-03-13

    997398 wrote:
    Could you please tell me, which oracle commands can get below result?
    1. Total size of archive generated
    TotalArchive (GB) Date
    24.415 28-02-2013
    14.223 29-03-2013
    12.133 30-02-2013
    2. Total number of archive logs generated
    COUNT(SEQUENCE#) TO_CHAR
    123 28-03-13
    234 29-03-13
    124 30-03-13query V$LOG

  • Oracle.jbo.NoDefException: JBO-25002: Definition oracle.epm.planning.applic

    All,
    Want some pointers to the error that I am running into. The application supports webcenter and when we bring up the web page we get the error below
    oracle.jbo.NoDefException: JBO-25002: Definition oracle.epm.planning.application.ui.DataControls of type null is not found
    caused by the nested error Caused by: oracle.mds.core.MetadataNotFoundException: MDS-00013: no metadata found for metadata object "/oracle/epm/planning/application/ui/DataControls.dcx"
    at oracle.mds.core.MetadataObject.getBaseMO(MetadataObject.java:1279)
    There is no file called DataControls.dcx under the "/oracle/epm/planning/application/ui/ package.
    How do we remove the runtime reference that webcenter still seems to hold onto?
    Any help is really appreciated.

    It supports WebCenter Customizable Components tag library in the ViewController project. The DataControls.dcx file which was under the oracle.epm.planning.application.ui package was still present under the classes folder. Since this file was deleted from the JDEV view it seemed that it should not be included. It worked on my environment but not for others who did not have the file stored under classes folder under the ViewController project.
    I have the problem resolved now. Thanks for all the pointers.

  • Oracle Hyperion Planning and Budgetting

    We are planning to use the Oracle Hyperion Planning and Budgetting Product for our organization.And we are in the process of finding the best practice OR best suite Database software for Oracle Hyperion.
    Which database software product is best suite for Oracle Hyperion Planning and Budgetting?
    Our Source Systems
    Oracle E-Business Suite R12
    PeopleSoft Campus Solution
    Appreciate your commnets on this matter... Thanks

    Hi,
    you can try the following:
    Go to [http://service.sap.com/bosap-support] and navigate to Documention->Product Guides . Select SAP BPC and you should get the links to the related documentation.
    If you still get problems to access it, you must issue a message to SAP (service.sap.com/support) asking them to allow you accessing the documentation on SAP BPC.
    Regards,
    Stratos

  • Oracle BAM Plan Monitor does not start

    Hello all,
    the Oracle BAM Plan Monitor does not start in when I execute the start scripts.
    It tells my that the name of the service is invalid.
    Is there any possibility to check on the configuration for that service name?
    I have also checked on the event log of my Windows machine. There are a couple of strange entries coming from the Oracle BAM Engine:
    EventEngine: ADC Context exception ADC Server exception in GetUserGroups(): 2.
    ActiveDataCache: Caught exception while validating user NT-AUTORITÄT\SYSTEM: The RPC-Server is not available
    Maybe someone has a clue how to resolve this issue.

    Hi
    Are you using a valid user name and passwd to access the plan monitor?
    Did you set up a user called 'BAM' in your Enterprise Link? Normally this user will get created automaticaly while installing BAM. If it doesnt exist, you will have to create a user called BAM in EL with a blank password.
    Please follow the post installation document, that is having more details.
    Thanks
    Laj

  • Oracle Hyperion Planning Plus Tool

    Hi All,
    Any one knows about "Oracle Hyperion Planning Plus". From internet I came to know that its a Microsoft Excel and Web-based budgeting and forecasting tool.
    If any has more information about this tool/any documentation/documentation links....please share with me.....
    Thanks,
    Naveen Suram

    You can check the link below for further info.
    http://www.oracle.com/appserver/business-intelligence/hyperion-financial-performance-management/hyperion-planning.html
    Hyperion Planning Plus is the name of bundle being sold by Oracle which includes reporting tools around Hyperion Planning.
    Cheers
    Alp

  • How to decide explain plan is optimal?

    hi All,
    could you please tell me on what basis we can decide explain plan is optimal.
    Thanks,
    Santosh.

    <If possible I don't recommend using AUTOTRACE since it requires actual execution of a sql>
    Good observation. But it you want the statistics you have to run the statement anyway, and its easier than doing a trace and using TKPROF. You can also turn off query execution by using SET AUTOTRACE TRACEONLY EXPLAIN but if you get it wrong the query will still execute :)
    EXPLAIN PLAN is better when you want to be certain to just get a plan. Plus, the output from DBMS_XPLAN (9iR2 and later) is I feel easier to read.
    GUI tools like TOAD are great - if you can get them. My workstation is locked down and I can't load anything that requires registry changes; a TOAD installation failed last week. I have SQL*DEVELOPER but have to re-load the connection settings (they're stored in an HTML file) when I start it

  • Can i access the Oracle Demand Planning Cubes using the AWM?

    Hi All,
    Is it possible to access the Oracle Demand planning data which is stored as Express server using the Analytic workspace manager?
    Any information regarding this is really appreciated.

    Abdul Hafeez,
    Is ODP using Express Server or Oracle OLAP Analytical workspaces?
    If Express Server is being used by ODP, then you cannot create sql views for OBIEE.
    If Oracle database is being used for ODP data, then it is storing the data in Analytical workspaces. In that case, you can manually create OLAP views using OLAP_TABLE function. To do that, you will first have to know all the required structures inside the Analytical workspaces. Without that knowledge, you will not know what olap structures to "expose" in the OLAP views.
    You can read about OLAP_TABLE function from Oracle 10g documentation http://download.oracle.com/docs/cd/B19306_01/olap.102/b14350/olap_table.htm
    If you are using 9i database for ODP, then read about OLAP_TABLE function from 9i documentation http://download.oracle.com/docs/cd/B10501_01/olap.920/a95295/olap_tab.htm
    - Nasar

  • Which plan is fast

    hi,
    i m using oracle 10g , i want to know which plan would do fast search.
    i have zone wise data ,around 30 zones and would have data in terabytes.
    so should i create partition table according to zone .
    or
    should i create 35 zone table .
    which plan would provide me fast searching result or is there some other way ?
    regards

    Girish Sharma wrote:
    So, is it a documentation bug, link posted by sb; which is saying :
    The optimizer compares the costs of the plans and chooses the one with the lowest cost. ?It is not saying that the plan with the lowest cost is the fastest one, does it ? So, no Oracle doc bug, optimizer is really choosing the plan with lowest cost but that does not means this will be the fastest way.
    The cost must be defined what we are talking about, it is a set of criteria, not only the time.
    Between your home and your office, there is a straight road which represent the lowest cost in term of fuel and distance. Unfortunately, there is often traffic jump over there, so it could be faster to take a an other way, but need several kilometers more (you'll spent more money in fuel, and distance is also more). Whether the first has the lowest cost - and it would be the first advise based on cost (based on the cost definition we give), the second way will be the fastest way to reach your home from office - this would be the first advise based on experience (and it is also depend on the time you leave the office).
    Nicolas.

  • Oracle rapid planning

    Hi all ,
    I wanted to know , what the oracle rapid planning is all about ... If any body give me brief discription about rapid planning, it will be great help for me.
    Please pont me to any document about oracle rapid planning.
    Regards

    Oracle Rapid Planning is a new product launched in 2009 in the VCP suite of oracle.
    It helps in following:
    1. It is an easier way of replanning.
    2. The GUI is so user friendly that its gives you feeling as if you are working on excel sheet.
    3. Earlier oracle ASCP simulation performance issues are being handled in this product.
    4. It is well integrated to rest of the oracle VCP products.
    5. It helps in quick decision making by allowing What-If Analysis.
    6. It has inbuilt analytics which help users to analyze and compare the affect of changed parameters in replanning.
    7. It is a standalone product.

  • Oracle Execution Plan

    Hi!
    How come the Oracle execution plan doesn't show inner select statements?
    ie:
    select s.id, (select name from anothertable where id = s.id)
    from subs s
    where s.createdate < '20-March-2005'

    Which version of database are you running?
    When you run the following query on SCOTT schema, what type of plan do you get?
    SQL> set autotrace traceonly explain
    SQL> select d.*, (select sum(sal) from emp e where e.deptno = d.deptno) from dept d ;
    Execution Plan
       0      SELECT STATEMENT Optimizer=CHOOSE (Cost=2 Card=327 Bytes=981
              0)
       1    0   SORT (AGGREGATE)
       2    1     TABLE ACCESS (BY INDEX ROWID) OF 'EMP' (Cost=2 Card=3333
              3 Bytes=166665)
       3    2       INDEX (RANGE SCAN) OF 'IDX_EMP_DEPTNO' (NON-UNIQUE) (C
              ost=1 Card=33333)
       4    0   TABLE ACCESS (FULL) OF 'DEPT' (Cost=2 Card=327 Bytes=9810)
    SQL> disconnect
    Disconnected from Oracle9i Enterprise Edition Release 9.2.0.5.0 - Production
    With the Partitioning, OLAP and Oracle Data Mining options
    JServer Release 9.2.0.5.0 - Production
    SQL>

  • ALBPM vs Oracle SOA : Oracle Support Plan

    Folks,
    I have been looking for Oracle's Support Plan for AL BPM 6.5, Oracle BPM 10.3 and Oracle BPM 11G.
    Can you please tell me the planned end-dates for Support ( regular & Premium ) for these Products ? Can you please provide a link for any Document / presentation that outlines this information ?
    I am able to get similar information for various flavors & version of Oracle Database, but not for the BPM offerings.
    Thanks,
    Sandeep Seshan

    Folks,
    I found the answer - I got it in the Oracle Lifetime Support Policy Document at this link :-
    http://www.oracle.com/us/support/library/lifetime-support-middleware-069163.pdf
    I am not sure if I should mark this question as " answered " :)
    Thanks,
    Sandeep Seshan

  • Could anybody tell me which are the tools for diagnosting the APPs ?

    Hi,
    Could anybody tell me which are the tools for monitoring/ diagnosting the Oracle Apps ? Is any tool (Oracle or not) to monitor the concurrent manager?
    Thanks,
    Paul

    read this
    http://www.oracleappshub.com/11i/diagnostics-made-easy-oracle-diagnostic-tool/
    http://www.oracleappshub.com/11i/diagnostics-made-easy-oracle-diagnostic-tool-p/

  • Archived manually moved, how to tell Oracle?

    We used a temporary archivelog-destination. After this location was changed back to default the temporary location was dropped. Unfortunately there is 1 archive that was on the temporary storage which is copied to the default location that can not be backupped.
    RMAN-00571: ===========================================================
    RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
    RMAN-00571: ===========================================================
    RMAN-03002: failure of backup command at 11/09/2010 12:06:10
    RMAN-06059: expected archived log not found, lost of archived log compromises recoverability
    ORA-19625: error identifying file /data/oradata/reco01_tmp/DES9/DES9_0000138816.arc
    ORA-27037: unable to obtain file status
    SVR4 Error: 2: No such file or directory
    Additional information: 3
    How can I tell Oracle to look in /data/oradata/reco01 ?

    If the archive log is now in the new location then you have catalog the archivelog
    CATALOG ARCHIVELOG '/u032/oradata/archive1_30.arc'
    But you need to provide more information example are you using recovery catalog, what is DB and OS versions?
    Thanks.

  • Oracle Demand Planning or Demantra?

    It seems fairly obvious that if you are starting out an implementation (or even part way through), you would cease implementing Oracle Demand Planning (ODP) and implement Demantra. I have read that all development work was ceased on ODP (even though some new features have been implemented in ODP R12). Further, I have read that there is no simple migration path from ODP to Demantra (due to the very different data structures).
    My questions:
    1. Do you agree with my comment about ceasing the implementation of ODP and resuming with ODP, and if not, why not?
    2. Is there any known migration path between the two products that is supported by Oracle or is a completely new implementation needed?
    3. What are the comparative costs of the two products?
    4. What are the technology stack requirements of the two products? (particulary of Demantra).
    Thanks, as always.

    with regards to point 1... demantra is a better tool; it will create better forecast numbers and will provide a much more sophisticated end user experience. however the answer to your question is not always an obvious one.
    firstly lets talk about finance and schedule. ceasing an implementation that is costing a large sum of money in favour of a newer product may not be the right course of action. budget alarm bells will start ringing since the delivery schedule will now be off the chart and the costs will only go up. is the implementation required to fix legacy system and data problems? if so there will be groans from the people that need the forecast numbers when they hear that the current inaccuracy will continue because some fabled "even better numbers" will be available somewhat later than promised.
    what about stability? odp has it's fair share of problems but it is still much more robust than oracle demantra and depending on factors such as company size, structure, product life-cycle, forecast horizon and methodology demantra may not even provide a better solution. an r12 implementation of odp would survive for a number of years before requiring an upgrade and by then newer and better versions of oracle demantra will be available. there are a lot of customers still using odp and oracle will continue to support them.
    don't forget the bigger picture and plan for the future. planning and forecasting solutions need to be flexible - whatever solution you use you should expect that it will need to evolve and part of that evolution should be a product migration. if the planners that are expected to use the new tools and process are not yet skilled at forecasting (maybe they just manipulate numbers in excel based upon weekly meetings?) then the basic approach to skills development might be as follows: start simple, then develop a more sophisticated approach and finally create a sophisticated forecasting solution (this pathway could take years). if you don't yet know the medium or advanced strategy then how can you possibly know which tool is best suited? start simple with odp knowing that in two years when you will want to move to a more advanced forecasting approach your users will understand what they want. at that point you can decide whether to stick or twist.
    as for the other questions: 2 is a no. 3 & 4: don't know (sorry)
    good luck and let us know what you decide.

Maybe you are looking for