Wrong Execution Plan getting picked on some occassions

 
Hi,
The following query sometimes runs efficiently; gives quick results, CPU and IO utilization is also up to the mark. But sometimes the query takes very long time to execute.
At that time I do not observe any blocks as well. Also the CPU and IO is too huge for running this query. It seems the engine picks up wrong execution plan some times.
This query is fired through some product. So there is no scope to change the query. Any suggestions for the engine to pick up right execution plan?
select i . bpd_instance_id as instanceId , i . instance_name as instanceName , bpd . name as bpdName , istatus . name as instanceStatus , t . subject as taskSubject , tpriority . name as taskPriority , t . due_date as taskDueDate , t . attached_form_ref as taskAttachedInfoPathFormRef , t . attached_ext_activity_ref as taskAttachedExtActivityRef , t . task_id as taskId , tstatus . name as taskStatus , tuser . user_name as assignedToUser , tpriority . ranking as taskPriorityRanking from msadmin.lsw_task t with ( nolock ) inner join msadmin.lsw_bpd_instance i with ( nolock ) on t . bpd_instance_id = i . bpd_instance_id left join msadmin.lsw_task_status_codes tstatus on t . status = tstatus . status_value left join msadmin.lsw_bpd_status_codes istatus on i . execution_status = istatus . status_id left join msadmin.lsw_priority tpriority on t . priority_id = tpriority . priority_id left join msadmin.lsw_bpd bpd on i . cached_bpd_version_id = bpd . version_id left join msadmin.lsw_usr_xref tuser on t . user_id = tuser . user_id where ( t . status in ( '11','12' ) and ( t . user_id = 5909 or t . task_id in (
select t . task_id
from msadmin.lsw_task t with ( NOLOCK )
inner join msadmin.lsw_usr_grp_mem_xref m with ( NOLOCK )
on t . group_id = m . group_id
where m . user_id = 5909
and t . user_id = -1
) or t . task_id in (
select t . task_id
from msadmin.lsw_task t with ( NOLOCK )
inner join msadmin.lsw_grp_grp_mem_exploded_xref x with ( NOLOCK )
on t . group_id = x . container_group_id
inner join msadmin.lsw_usr_grp_mem_xref m with ( NOLOCK )
on m . group_id = x . group_id
where m . user_id = 5909
and t . user_id = -1
) ) ) order by taskDueDate , taskPriorityRanking , instanceId , taskId

Is it a good practive to update a stat nightly on all the tables with FULL SCAN? will it help to boost the performance?
Maybe. But it may also be overkill, particularly if you do not have the hours. A somewhat better option may be to run with FULLSCAN, INDEX to only update the statistics for indexes. But note that if you rebuild an index, that updates the statistics for that
index with FULLSCAN anyway.
But overall, there are rarely any magic button to performance tuning. In the end, you will need to do the hard work to find the painful queries that need better indexes or needs to be rewritten.
Erland Sommarskog, SQL Server MVP, [email protected]

Similar Messages

  • Sometime wrong endpoint URL getting picked up at runtime at adapter engine

    Hi experts,
    In our production XI box, sometime wrong endpoint URL getting picked up at runtime at adapter engine.
    But this scenario does not happen always. It happens sometime. I have checked url for integration engine in
    SLD and also RWB->Component monitoring->integration engine, but in both the places it is correctly specified.
    It is very difficult to find the root cause...please help
    Thanks,
    Nayan

    Hi Christian,
    May be it is a cluster problem...actual URL must be the URL of the cluster not any specific SAP server box....but in our case sometimes URL points to any SAP server  that may or may not be within that cluster.
    Please give some solution to rectify it.
    Thanks,
    Nayan

  • Wrong Pricing Procedure getting picked up in Value Contract

    While creating Value Contract, when we maintain conditions, the condition type which we want to maintain are missing.
    During a year, PO is made a for a value of around 15 crores. So we need to make  contract which will pick up the same pricing procedure which is picked up for all those PO's. The pricing procedure was specially created for these PO's.
    Now while we create contract it should pick up that same pricing procedure which it picks up in the PO.
    The vendor, material & Purchase Org is same in our contract as it is there in the PO.     
    So I feel when we create a contract it should pick the same pricing procedure as it does for PO's, but our contract picks some other pricing procedure.
    what is the configuration to be done specially for Value contract.
    Regards,
    Karthik

    Hi,
    The pricing procedure is determined differenetly for contract & PO .
    For PO, pricing procedure is determined by the Vendor Schema Group and Purchase Org Schema Group.
    But in case of Contract the pricing procedure is based on condition supplements of condition type PB00.
    Condition type PB00 is considered as master condition type in case of Pricing procedure of contract.
    In std SAP contract system picks up RM0001or  RM1001 because these pricing procedures are maintained in the Condition Supplements of PB00.
    If you want to have pricing procedure other than RM0001 or RM1001 then you need to maintain that pricing procedure in the Condition Supplement of condition type PB00.
    Regards

  • Wrong business system getting picked up

    hi
    I have a SAP  A to SAP B ( sync proxy to Proxy ) scenario...
    Here I have created a Business system called SAP_BACKEND for SAP A...
    When a message is sent from SAP A and I check in SXMB_Moni in SAP A the sender system is not SAP_BACKEND but R3_SAP like that
    how do i change this because this is giving me no receiver determined error

    SAP_BACKEND is pointing to the tech system and client of SAP A...
    Also I have imported it correctly in  ID....
    R3_SAP is not in SLD.....
    How do I check the integration engine config of SAP A ( I checked in SXMB_ADM->integration engine config and it is pointing to PI )
    My observation -- SAP A was earlier pointing to some other PI system . could this be a problem?

  • How to delete stored execution plan?

    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...

    Thank you for reading!
    The solution is:
    Add parameter no_invalidate => FALSE at the gather_table_stats call:
    exec dbms_stats.gather_table_stats(ownname=>'xxxx', tabname=>'yyyy', no_invalidate=>FALSE);

  • How to fix different execution plan for different bind variable values?

    Please find the below query. The execution plan is fine. The problem That I am facing is in some cases for different bind variable values execution plan gets changed and degrades performance. I have used 6 tables here and all of the tables have histogram on all columns. Database version is Oracle 10g and the value of method_opt is 'For all columns size auto'
    SELECT l.LineNumber INTO :b0
    FROM Lines l ,LineVersions lv ,Statuses s
    WHERE (((((((((((l.serviceContractId=:b1 AND l.LineId<>:b2)
    AND lv.LineId=l.LineId) AND lv.StatusId=s.StatusId)
    AND s.Code IN ('EPR','ERE','EEP','ERP','PRP','PRD','AAC'))
    AND NOT (s.CODE='AAC' AND lv.activeto<TO_DATE(:b3,:b4)))
    AND lv.EquipmentDetailId=:b5) AND lv.RouteDetailId=:b6)
    AND (lv.cargoDetailId=:b7 OR lv.cargoDetailId IN
    (SELECT i_cd1.cargoDetailId
    FROM CargoDetails i_cd1 ,CargoDetails i_cd2 ,CargoCommodities i_cc1 ,
    CargoCommodities i_cc2 WHERE
    ((((((i_cd2.cargoDetailId=:b7 AND i_cd1.cargoDetailId<>:b7)
    AND i_cd1.ServiceContractId=:b1) AND i_cd1.cargoTypeId=i_cd2.cargoTypeId)
    AND i_cc1.cargoDetailId=i_cd1.cargoDetailId)
    AND i_cc2.cargoDetailId=i_cd2.cargoDetailId)
    AND i_cc1.commodityId=i_cc2.commodityId))))
    AND ((lv.customerGroupId IS NULL AND :b11=0) OR lv.customerGroupId IN
    (SELECT cgm1.customerGroupId
    FROM CustomerGroupMembers cgm1 ,CustomerGroupMembers cgm2 ,CustomerGroups cg1
    WHERE (((cgm2.customerGroupId=:b11 AND cgm1.customerNoId=cgm2.customerNoId)
    AND cg1.CustomerGroupId=cgm1.CustomerGroupId)
    AND cg1.ServiceContractId=l.ServiceContractId)))) AND lv.linetype='C')
    AND ROWNUM=1)
    After searching in several blogs I have found the below solutions. Please see it and let me know it is correct or not
    Solution 1:-Get rid of histogram that does nothing but messes up execution plan by giving below command
    exec dbms_stats.gather_table_stats(owner, tablename, method_opt => 'for all columns size 1', cascade => true);
    As 6 tables are there I need to execute above command 6 times.
    Solution 2:- Use stored outline. Not sure how to get the best execution plan.
    I am looking for answers ASAP. Thanks in advance

    As you have probably read, bind variables and histograms do not mix well.
    Histograms suggest that you have skew in your data such that different values should get different plans
    Bind variables exist so that SQL with different supplied values can be shared.
    Mix the two together and at parse time with bind variable peeking you get plans for specific values shared for all values.
    The solutions you have mentioned are the common approaches, together with a third - use literals not binds if you've got data skew (i.e. your histograms are justified) and don't want shared SQL.
    I would have thought that getting rid of some of these histograms may be the right approach if you're none of your application SQL is using literals to benefit from them.
    Can you confirm your version of Oracle.
    Further reading:
    http://jonathanlewis.wordpress.com/2009/05/06/philosophy-1/
    http://structureddata.org/2008/03/26/choosing-an-optimal-stats-gathering-strategy/
    http://richardfoote.wordpress.com/2008/01/04/dbms_stats-method_opt-default-behaviour-changed-in-10g-be-careful/

  • How to capture the execution plan for a query

    HI All,
    Can anyone please help me in finding out the command to capture the execution plan for a query.
    Execution plan for select * from EMP where <Condtions>
    it is getting executed successfully but i need to get the proper execution plan for the same.
    Thanks

    971830 wrote:
    i want to know where execution plan gets generated??
    in PMON of server process or in shared pool??
    i know that optimixer create execution plan..It is stored in Library Cache (present inside Shared Pool ).
    select * from v$sql_plan;An absolute beautiful white paper :
    Refer this -- www.sagelogix.com/sagelogix/SearchResults/SAGE015052
    Also -- http://www.toadworld.com/KNOWLEDGE/KnowledgeXpertforOracle/tabid/648/TopicID/XPVSP/Default.aspx
    HTH
    Ranit B.

  • How to get rid of 'BITMAP CONVERSION' in Execution Plan.

    Hi I am using oracle 10g.
    I am getting the path of execution of the query something as below. I have posted some part of it not all.
    I want to get rid of this 'BITMAP CONVERSION' Section of the path, is there any hint for the same in oracle?
    |  56 |      TABLE ACCESS BY INDEX ROWID      | XMVL_ONLINE_VIEW_BASE         |  7274 |  1662K|       |  3320  (21)| 00:00:17 |
    |  57 |       BITMAP CONVERSION TO ROWIDS     |                               |       |       |       |            |          |
    |  58 |        BITMAP AND                     |                               |       |       |       |            |          |
    |  59 |         BITMAP OR                     |                               |       |       |       |            |          |
    |  60 |          BITMAP CONVERSION FROM ROWIDS|                               |       |       |       |            |          |
    |  61 |           SORT ORDER BY               |                               |       |       |       |            |          |
    |  62 |            INDEX RANGE SCAN           | IDX_XMVLONLINEVIEW_BCOMPANYPK |       |       |       |     4  (50)| 00:00:01 |
    |  63 |          BITMAP CONVERSION FROM ROWIDS|                               |       |       |       |            |          |
    |  64 |           SORT ORDER BY               |                               |       |       |  3608K|            |          |
    |  65 |            INDEX RANGE SCAN           | IDX_XMVLONLINEVIEW_BCOMPANYPK |       |       |       |     4  (50)| 00:00:01 |
    |  66 |         BITMAP CONVERSION FROM ROWIDS |                               |       |       |       |            |          |
    |  67 |          SORT ORDER BY                |                               |       |       |  3288K|            |          |
    |  68 |           INDEX RANGE SCAN            | IDX_XMVLVIEW_UPPERVENDORNAME  |       |       |       |    59  (45)| 00:00:01 |

    Mark,
    Please check below link :
    http://www.orafaq.com/node/1420
    In the above link there is a query :
    EXPLAIN PLAN FOR
    SELECT *
    FROM ef_actl_expns
    WHERE lbcr_sk IN (
    SELECT lbcr_sk
    FROM ed_lbr_cst_role
    WHERE lbr_actv_typ_cd = 'A'
    If it is ALTER SESSION SET OPTIMIZER_MODE = 'FIRST_ROWS' then there is "BITMAP CONVERSION TO ROWIDS" in the execution plan, but if it is ALTER SESSION SET OPTIMIZER_MODE = 'FIRST_ROWS_1' then there is no "BITMAP CONVERSION" in the plan. So, can we suggest to OP to go for ALTER SESSION SET OPTIMIZER_MODE = 'FIRST_ROWS_1' ?
    But yes, as you stated that what is 4 digit of Oracle version is also mising in the above link. I am just asking that is it good to go with ALTER SESSION SET OPTIMIZER_MODE = 'FIRST_ROWS_1' please ? Because generally in the execution plan "BITMAP CONVERSION" happens for star transformation so, I think below link may also be interest to OP :
    http://docs.oracle.com/cd/B19306_01/server.102/b14223/schemas.htm
    Regards
    Girish Sharma

  • I seem to have picked up some sort of virus or bug of some kind.  I'm getting personals ads throughout my Facebook and yahoo home page.  i've tried CCleaner and it takes them off but only for a short time so i downloaded iantivirus but that found nothing

    i seem to have picked up some sort of virus or bug of some kind.  I'm getting personals ads throughout my Facebook and yahoo home page.  i've tried CCleaner and it takes them off but only for a short time so i downloaded iantivirus but that found nothing

    It may not be a good soloution for a novice, but I have been using hosts files to block unwanted URLs for many years with zero disasters and lots of positive results.
    As I noted, whenever I find a new "bad" site, I simply add the name to my hosts file. It takes a few seconds and then it's gone forever. I find no difficulty whatsoever.
    No, it's not for everyone, which is why I gave no specific details; but for those who are interested and have the desire to learn about these hosts files, it is a very good way to avoid "bad" websites.
    I also enjoy the "clean" view of a webpage when there are no ads showing at all. The page loads faster and  the distractions are gone.
    I never realized how much junk I am supressing until I got my iPad and saw all those horrid ads that are blocked on my other computers.
    Here is a typical result of properly using a hosts file:
    I love it when a plan comes together - -  H. Smith.

  • How to get the SQL Execution Plan from complex Extractors ?

    Hi
    I am looking for a way to get  the
    SQL Execution Plan(s!) 
    from
    Complex Extractors like 0CO_OM_CCA_9 ?
    Anybody has got a suggestion ?
    How to get this in SM50 ?
    ThanXs
    Martin

    Identifying the query is the hard part. If you can identify it(based on table access or some such parameter, getting the execution plan is easy in ST04 .

  • How to get execution plan in a CLOB?

    Hello,
    I want to get execution plans of a query in a CLOB format. I am trying to run following query against v$sql view. One of the columns I want is the execution plan for the query. I am getting following error. Eventually, I am going to insert this data into a log table to keep history of all SQLs and their execution plans.
    How can I do that?
    Thank you in advance.
    SQL> SELECT sql_id,
      2         plan_hash_value,
      3         TO_CLOB (DBMS_XPLAN.display_awr (sql_id            => sql_id,
      4                                          plan_hash_value   => plan_hash_value,
      5                                          format            => '+PEEKED_BINDS'))
      6            sql_plan_clob,
      7         buffer_gets,
      8         executions
      9    FROM v$sql
    10   WHERE ROWNUM < 5;
           TO_CLOB (DBMS_XPLAN.display_awr (sql_id            => sql_id,
    ERROR at line 3:
    ORA-00932: inconsistent datatypes: expected NUMBER got SYS.DBMS_XPLAN_TYPE_TABLE

    try first
    select *
      from table(DBMS_XPLAN.display_awr(sql_id          => sql_id,
                                        plan_hash_value => plan_hash_value,
                                        format          => '+PEEKED_BINDS'
                )to see the table returned
    then try to adapt http://asktom.oracle.com/pls/apex/f?p=100:11:0::::P11_QUESTION_ID:68212348056 to produce fixed length rows.
    look for describe_columns procedures in http://docs.oracle.com/cd/E11882_01/appdev.112/e25788/d_sql.htm#i1025449 for column length information available in internal tables and write the rows directly to clob instead of writing to disk and loading your clob from there.
    Regards
    Etbin
    Edited by: Etbin on 31.10.2012 19:56
    pointing to dbms_sql package added

  • Unable to get the execution plan when using dbms_sqltune (11gR2)

    Hi,
    Database version: 11gR2
    I have a user A that is granted privileges to execute dbms_sqltune.
    I can create a task, excute it and run the report.
    But, when I run the report I get the following error:
    SQL> show user
    USER is "A"
    SQL> set long 10000 longchunksize 10000 linesize 200 pagesize 000
    select dbms_sqltune.report_tuning_task(task_name => 'MYTEST') from dual;SQL>
    GENERAL INFORMATION SECTION
    Tuning Task Name : MYTEST
    Tuning Task Owner : A
    Workload Type : Single SQL Statement
    Scope : COMPREHENSIVE
    Time Limit(seconds): 1800
    Completion Status : COMPLETED
    Started at : 05/15/2013 11:53:22
    Completed at : 05/15/2013 11:53:23
    Schema Name: SYSMAN
    SQL ID : gjm43un5cy843
    SQL Text : SELECT SUM(USED), SUM(TOTAL) FROM (SELECT /*+ ORDERED */
    SUM(D.BYTES)/(1024*1024)-MAX(S.BYTES) USED,
    SUM(D.BYTES)/(1024*1024) TOTAL FROM (SELECT TABLESPACE_NAME,
    SUM(BYTES)/(1024*1024) BYTES FROM (SELECT /*+ ORDERED USE_NL(obj
    tab) */ DISTINCT TS.NAME FROM SYS.OBJ$ OBJ, SYS.TAB$ TAB,
    SYS.TS$ TS WHERE OBJ.OWNER# = USERENV('SCHEMAID') AND OBJ.OBJ# =
    TAB.OBJ# AND TAB.TS# = TS.TS# AND BITAND(TAB.PROPERTY,1) = 0 AND
    BITAND(TAB.PROPERTY,4194400) = 0) TN, DBA_FREE_SPACE SP WHERE
    SP.TABLESPACE_NAME = TN.NAME GROUP BY SP.TABLESPACE_NAME) S,
    DBA_DATA_FILES D WHERE D.TABLESPACE_NAME = S.TABLESPACE_NAME
    GROUP BY D.TABLESPACE_NAME)
    ERRORS SECTION
    - ORA-00942: table or view does not exist
    SQL>
    It seems there a missing privileg for dislaying the execution plan.
    As a workaround, this is solved by granting select any dictionay (which I don't want) to the user A.
    Does someone have an idea about what privilege is missing?
    Kind Regards.

    Hi,
    SELECT ANY DICTIONARY system privilege provides access to SYS schema objects only => which you are using as workaround
    SELECT_CATALOG_ROLE provides access to all SYS views only.==> Safe option
    SQL> grant SELECT ANY DICTIONARY to test;
    Grant succeeded.
    SQL> conn test/test
    Connected.
    SQL> select count(*) from  sys.obj$;
      COUNT(*)
         13284
    SQL> conn /as sysdba
    Connected.
    SQL> revoke SELECT ANY DICTIONARY from test;
    Revoke succeeded.
    SQL> grant SELECT_CATALOG_ROLE to test;
    Grant succeeded.
    SQL> conn test/test
    Connected.
    SQL> select count(*) from  sys.obj$;
    select count(*) from  sys.obj$
    ERROR at line 1:
    ORA-00942: table or view does not existHTH

  • Security question keep saying they are wrong and I know they are right. I can't change them cuz when I try it tells me to answer the questions. I have tried everything changing my account and all and still can't get it can some one please help me out.

    Security question keep saying they are wrong and I know they are right. I can't change them cuz when I try it tells me to answer the questions. I have tried everything changing my account and all and still can't get it can some one please help me out.

    Go here and select "Reset your password."  You will receive an email message with a link that bypasses the questions.  You will then be able to select and answer the questions again.

  • CBO not picking the right execution plan

    Database: Oracle 9.2.0.6 EE
    OS:Solaris 9
    I am trying to tune a query that is generated via Siebel Analytics. I am seeing a behaviour which is puzzling me but hopefully would be 'elementary' for someone like JPL.
    The query is based on a total of 7 tables. If I comment out any 2 dimension tables, the query picks up the right index on the fact table. However, the moment I add another table to the query, the plan goes awry.
    The query with 5 tables is as below:
    select count(distinct decode( T30256.HEADER_FLG , 'N' , T30256.ROW_WID ) ) as c1,
    T352305.DAY_DT as c2,
    case  when T44643.PRODUCT_CLASS_NAME = 'MobileSubscription' then T40081.ATTR15_CHAR_VAL else 'Unspecified' end  as c3,
    T352305.ROW_WID as c5
    from
                   W_PRODUCT_D T30955,
                   W_PRDATTRNM_D T44643,                         
                   W_DAY_D T352305,                 
                   W_ORDERITEM_F T30256,              
                   W_PRDATTR_D T40081                         
    where  ( T30955.ROW_WID = T44643.ROW_WID
    and T30256.LAST_UPD_DT_WID = T352305.ROW_WID
    and T30256.PROD_ATTRIB_WID = T40081.ROW_WID 
    and T30256.PROD_WID = T30955.ROW_WID
    and T30955.PROD_NAME = 'Mobile Subscription'
    and (case  when T44643.PRODUCT_CLASS_NAME = 'MobileSubscription' then T40081.ATTR15_CHAR_VAL else 'Unspecified' end  in ('BT150BB-18M', 'BT250BB-18M', 'BT50BB-18M', 'BT600BB-18M'))
    and T352305.DAY_DT between TO_DATE('2008-09-27' , 'YYYY-MM-DD') - 7 and TO_DATE('2008-09-27' , 'YYYY-MM-DD') - 1
    group by
    T352305.ROW_WID, T352305.DAY_DT,
    case  when T44643.PRODUCT_CLASS_NAME = 'MobileSubscription' then T40081.ATTR15_CHAR_VAL else 'Unspecified' end
    ;And the execution plan is as below:
    | Id  | Operation                        |  Name                | Rows  | Bytes | Cost (%CPU)|
    |   0 | SELECT STATEMENT                 |                      |   269 | 25824 | 18660   (3)|
    |   1 |  SORT GROUP BY                   |                      |   269 | 25824 | 18660   (3)|
    |   2 |   NESTED LOOPS                   |                      |   269 | 25824 | 18658   (3)|
    |   3 |    NESTED LOOPS                  |                      |  6826 |   579K|  4734   (3)|
    |   4 |     MERGE JOIN CARTESIAN         |                      |     8 |   544 |     6  (17)|
    |   5 |      NESTED LOOPS                |                      |     1 |    54 |     4  (25)|
    |   6 |       TABLE ACCESS BY INDEX ROWID| W_PRODUCT_D          |     1 |    37 |     3  (34)|
    |*  7 |        INDEX RANGE SCAN          | W_PRODUCT_D_M2       |     1 |       |     2  (50)|
    |   8 |       TABLE ACCESS BY INDEX ROWID| W_PRDATTRNM_D        |     1 |    17 |     2  (50)|
    |*  9 |        INDEX UNIQUE SCAN         | W_PRDATTRNM_D_P1     |     1 |       |            |
    |  10 |      BUFFER SORT                 |                      |     8 |   112 |     4   (0)|
    |  11 |       TABLE ACCESS BY INDEX ROWID| W_DAY_D              |     8 |   112 |     3  (34)|
    |* 12 |        INDEX RANGE SCAN          | W_DAY_D_M39          |     8 |       |     2  (50)|
    |  13 |     TABLE ACCESS BY INDEX ROWID  | W_ORDERITEM_F        |   849 | 16131 |   592   (3)|
    |* 14 |      INDEX RANGE SCAN            | W_ORDERITEM_F_INDX9  |   852 |       |     4  (25)|
    |* 15 |    INDEX RANGE SCAN              | W_PRDATTR_D_M29_T1   |     1 |     9 |     3  (34)|
    ----------------------------------------------------------------------------------------------Note how the dimension tables W_PRODUCT_D & W_DAY_D are joined using cartesian join before joining to the fact table W_ORDERITEM_F using the composite index 'W_ORDERITEM_F_INDX9'. This index consists of LAST_UPD_DT_WID, PROD_WID and ACTION_TYPE_WID, which are foreign keys to the dimension tables.
    Now if I add one more table to the query:
    select count(distinct decode( T30256.HEADER_FLG , 'N' , T30256.ROW_WID ) ) as c1,
                  T352305.DAY_DT as c2,
                   case  when T44643.PRODUCT_CLASS_NAME = 'MobileSubscription' then T40081.ATTR15_CHAR_VAL else 'Unspecified' end  as c3,
                   T30371.X_BT_DLR_GROUP as c4,
                   T352305.ROW_WID as c5
              from                W_PRODUCT_D T30955,
                   W_PRDATTRNM_D T44643,                         
                   W_DAY_D T352305,                 
                   W_ORDERITEM_F T30256,              
                   W_ORDER_D T30371,                                            
                   W_PRDATTR_D T40081                         
              where  ( T30955.ROW_WID = T44643.ROW_WID
              and T30256.LAST_UPD_DT_WID = T352305.ROW_WID
              and T30256.PROD_ATTRIB_WID = T40081.ROW_WID
              and T30256.PROD_WID = T30955.ROW_WID
              and T30256.ORDER_WID = T30371.ROW_WID
              and T30955.PROD_NAME = 'Mobile Subscription'
              and T30371.STATUS_CD = 'Complete'
              and T30371.ORDER_TYPE = 'Sales Order' 
              and (case  when T44643.PRODUCT_CLASS_NAME = 'MobileSubscription' then T40081.ATTR15_CHAR_VAL else 'Unspecified' end  in ('BT150BB-18M', 'BT250BB-18M', 'BT50BB-18M', 'BT600BB-18M'))
              and T352305.DAY_DT between TO_DATE('2008-09-27' , 'YYYY-MM-DD') - 7 and TO_DATE('2008-09-27' , 'YYYY-MM-DD') - 1
              group by T30371.X_BT_DLR_GROUP, T352305.ROW_WID, T352305.DAY_DT,
              case  when T44643.PRODUCT_CLASS_NAME = 'MobileSubscription' then T40081.ATTR15_CHAR_VAL else 'Unspecified' end;I have added a single table W_ORDER_D to the query, and the execution plan is:
    | Id  | Operation                          |  Name               | Rows  | Bytes | Cost (%CPU)|
    |   0 | SELECT STATEMENT                   |                     |    44 |  6336 | 78695   (3)|
    |   1 |  SORT GROUP BY                     |                     |    44 |  6336 | 78695   (3)|
    |   2 |   NESTED LOOPS                     |                     |    44 |  6336 | 78694   (3)|
    |   3 |    NESTED LOOPS                    |                     |   269 | 27707 | 78145   (3)|
    |*  4 |     HASH JOIN                      |                     |  6826 |   626K| 64221   (3)|
    |   5 |      TABLE ACCESS BY INDEX ROWID   | W_DAY_D             |     8 |   112 |     4  (25)|
    |*  6 |       INDEX RANGE SCAN             | W_DAY_D_M39         |     1 |       |     3  (34)|
    |   7 |      TABLE ACCESS BY INDEX ROWID   | W_ORDERITEM_F       | 86886 |  2206K| 64197   (3)|
    |   8 |       NESTED LOOPS                 |                     | 87004 |  6797K| 64200   (3)|
    |   9 |        NESTED LOOPS                |                     |     1 |    54 |     4  (25)|
    |  10 |         TABLE ACCESS BY INDEX ROWID| W_PRODUCT_D         |     1 |    37 |     3  (34)|
    |* 11 |          INDEX RANGE SCAN          | W_PRODUCT_D_M2      |     1 |       |     2  (50)|
    |  12 |         TABLE ACCESS BY INDEX ROWID| W_PRDATTRNM_D       |     1 |    17 |     2  (50)|
    |* 13 |          INDEX UNIQUE SCAN         | W_PRDATTRNM_D_P1    |     1 |       |            |
    |* 14 |        INDEX RANGE SCAN            | W_ORDERITEM_F_N6    | 86886 |       |   212  (18)|
    |* 15 |     INDEX RANGE SCAN               | W_PRDATTR_D_M29_T1  |     1 |     9 |     3  (34)|
    |* 16 |    INDEX RANGE SCAN                | W_ORDER_D_N6        |     1 |    41 |     3  (34)|
    -----------------------------------------------------------------------------------------------Now CBO doesn't choose the composite index and the cost also has increased to 78695. But if I simply add an /*+ORDERED*/ hint to the above query, so that it should join the dimension tables before joining to fact table, then the cost drops to 20913. This means that CBO is not choosing the plan with the lowest cost. I tried increasing the optimizer_max_permutations to 80000, setting session level optimizer_dynamic_sampling to 8 (just to see if it works), but no success.
    Could you please advise how to overcome this problem?
    Many thanks.

    joshic wrote:
    Database: Oracle 9.2.0.6 EE
    OS:Solaris 9
    I am trying to tune a query that is generated via Siebel Analytics. I am seeing a behaviour which is puzzling me but hopefully would be 'elementary' for someone like JPL.
    The query is based on a total of 7 tables. If I comment out any 2 dimension tables, the query picks up the right index on the fact table. However, the moment I add another table to the query, the plan goes awry.
    I have added a single table W_ORDER_D to the query, and the execution plan is:
    Now CBO doesn't choose the composite index and the cost also has increased to 78695. But if I simply add an /*+ORDERED*/ hint to the above query, so that it should join the dimension tables before joining to fact table, then the cost drops to 20913. This means that CBO is not choosing the plan with the lowest cost. I tried increasing the optimizer_max_permutations to 80000, setting session level optimizer_dynamic_sampling to 8 (just to see if it works), but no success.Back to the original question:
    * Can you force the index usage of the composite index on W_ORDERITEM_F in the second query using an INDEX hint (instead of the ORDERED hint)? If yes, what does the plan look like, particularly what cost is reported?
    * Could you post the plans including the "Predicate Information" section below the plan output?
    * What is the definition of the index W_ORDERITEM_F_N6 on W_ORDERITEM_F?
    * Are the cardinalities reported in the execution plans close to reality or way off? The best way to verify this would be to run your query with SQL tracing enabled and generate a tkprof output. If you do so please post the tkprof output here as well.
    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/

  • How can I get an execution plan for a Function in oracle 10g

    Hi
    I have:
    Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi
    PL/SQL Release 10.2.0.4.0 - Production
    CORE 10.2.0.4.0 Production
    TNS for Solaris: Version 10.2.0.4.0 - Production
    NLSRTL Version 10.2.0.4.0 - Production
    I would like to know if is possible to get an EXECUTION PLAN for a FUNCTION if so, how can I get it ?
    Regards

    You can query the AWR data if your interesting SQL consumes enough resources.
    Here is a SQL*Plus script I call MostCPUIntensiveSQLDuringInterval.sql (nice name eh?)
    You'll need to know the AWR snap_id numbers for the time period of interest, then run it like this to show the top 20 SQLs during the interval:
    @MostCPUIntensiveSQLDuringInterval 20The script outputs a statement to run when you are interested in looking at the plan for an interesting looking statement.
    -- MostCPUintesticeSQLDuringInterval: Report on the top n SQL statements during an AWR snapshot interval.
    -- The top statements are ranked by CPU usage
    col inst_no             format      999 heading 'RAC|Node'
    col sql_id              format a16      heading 'SQL_ID'
    col plan_hash_value     format 999999999999 heading 'Plan|hash_value'
    col parsing_schema_name format a12      heading 'Parsing|Schema'
    col module              format a10      heading 'Module'
    col pct_of_total   format        999.99 heading '% Total'
    col cpu_time       format   999,999,999 heading 'CPU     |Time (ms)'
    col elapsed_time   format   999,999,999 heading 'Elapsed |Time (ms)'
    col lios           format 9,999,999,999 heading 'Logical|Reads'
    col pios           format   999,999,999 heading 'Physical|Reads'
    col execs          format    99,999,999 heading 'Executions'
    col fetches        format    99,999,999 heading 'Fetches'
    col sorts          format       999,999 heading 'Sorts'
    col parse_calls    format       999,999 heading 'Parse|Calls'
    col rows_processed format   999,999,999 heading 'Rows|Processed'
    col iowaits        format   999,999,999,999 heading 'iowaits'
    set lines 195
    set pages 75
    PROMPT Top &&1 SQL statements during interval
    SELECT diff.*
    FROM (SELECT e.instance_number inst_no
                ,e.sql_id
                ,e.plan_hash_value
                ,e.parsing_schema_name
                ,substr(trim(e.module),1,10) module
                ,ratio_to_report(e.cpu_time_total - b.cpu_time_total) over (partition by 1) * 100 pct_of_total
                ,(e.cpu_time_total - b.cpu_time_total)/1000 cpu_time
                ,(e.elapsed_time_total - b.elapsed_time_total)/1000 elapsed_time
                ,e.buffer_gets_total - b.buffer_gets_total lios
                ,e.disk_reads_total - b.disk_reads_total pios
                ,e.executions_total - b.executions_total execs
                ,e.fetches_total - b.fetches_total fetches
                ,e.sorts_total - b.sorts_total sorts
                ,e.parse_calls_total - b.parse_calls_total parse_calls
                ,e.rows_processed_total - b.rows_processed_total rows_processed
    --            ,e.iowait_total - b.iowait_total iowaits
    --            ,e.plsexec_time_total - b.plsexec_time_total plsql_time
          FROM dba_hist_sqlstat b  -- begining snap
              ,dba_hist_sqlstat e  -- ending snap
          WHERE b.sql_id = e.sql_id
          AND   b.dbid   = e.dbid
          AND   b.instance_number = e.instance_number
          and   b.plan_hash_value = e.plan_hash_value
          AND   b.snap_id = &LowSnapID
          AND   e.snap_id = &HighSnapID
          ORDER BY e.cpu_time_total - b.cpu_time_total DESC
         ) diff
    WHERE ROWNUM <=&&1
    set define off
    prompt  to get the text of the SQL run the following:
    prompt  @id2sql &SQL_id
    prompt .
    prompt  to obtain the execution plan for a session run the following:
    prompt  select * from table(DBMS_XPLAN.DISPLAY_AWR('&SQL_ID'));
    prompt  or
    prompt  select * from table(DBMS_XPLAN.DISPLAY_AWR('&SQL_ID',NULL,NULL,'ALL'));
    prompt .
    set define on
    undefine LowSnapID
    undefine HighSnapIDI guess you'll need the companion script id2sql.sql, so here it is:
    set lines 190
    set verify off
    declare
       maxDisplayLine  NUMBER := 150;  --max linesize to display the SQL
       WorkingLine     VARCHAR2(32000);
       CurrentLine     VARCHAR2(64);
       LineBreak       NUMBER;
       cursor ddl_cur is
          select sql_id
            ,sql_text
          from v$sqltext_with_newlines
          where sql_id='&1'
          order by piece
       ddlRec ddl_cur%ROWTYPE;
    begin
       WorkingLine :='.';
       OPEN ddl_cur;
       LOOP
          FETCH ddl_cur INTO ddlRec;
          EXIT WHEN ddl_cur%NOTFOUND;
          IF ddl_cur%ROWCOUNT = 1 THEN
             dbms_output.put_line('.');
             dbms_output.put_line('   sql_id: '||ddlRec.sql_id);
             dbms_output.put_line('.');
             dbms_output.put_line('.');
             dbms_output.put_line('SQL Text');
             dbms_output.put_line('----------------------------------------------------------------');
          END IF;
          CurrentLine := ddlRec.sql_text;
          WHILE LENGTH(CurrentLine) > 1 LOOP
             IF INSTR(CurrentLine,CHR(10)) > 0 THEN -- if the current line has an embeded newline
                WorkingLine := WorkingLine||SUBSTR(CurrentLine,1,INSTR(CurrentLine,CHR(10))-1);  -- append up to new line
                CurrentLine := SUBSTR(CurrentLine,INSTR(CurrentLine,CHR(10))+1);  -- strip off up through new line character
                dbms_output.put_line(WorkingLine);  -- print the WorkingLine
                WorkingLine :='';                   -- reset the working line
             ELSE
                WorkingLine := WorkingLine||CurrentLine;  -- append the current line
                CurrentLine :='';  -- the rest of the line has been processed
                IF LENGTH(WorkingLine) > maxDisplayLine THEN   -- the line is morethan the display limit
                   LineBreak := instr(substr(WorkingLine,1,maxDisplayLine),' ',-1); --find the last space before the display limit
                   IF LineBreak = 0 THEN -- there is no space, so look for a comma instead
                      LineBreak := substr(WorkingLine,instr(substr(WorkingLine,1,maxDisplayLine),',',-1));
                   END IF;
                   IF LineBreak = 0 THEN -- no space or comma, so force the line break at maxDisplayLine
                     LineBreak := maxDisplayLine;
                   END IF;
                   dbms_output.put_line(substr(WorkingLine,1,LineBreak));
                   WorkingLine:=substr(WorkingLine,LineBreak);
                END IF;
             END IF;
          END LOOP;
          --dbms_output.put(ddlRec.sql_text);
       END LOOP;
       dbms_output.put_line(WorkingLine);
       dbms_output.put_line('----------------------------------------------------------------');
       CLOSE ddl_cur;
    END;
    /

Maybe you are looking for

  • How can Hebrew letters in a pdf file be reproduced with Hebrew as a word doc using adobe export pdf?

    I subscribe to Adobe Export PDF and it has worked well. Today I uploaded a PDF file with Hebrew letters and the downloaded Word doc did not format the Hebrew letters as Hebrew letters. Is there a way around this? TYIA John

  • Switch iPad mini to PAL output through Lightning HDMI?

    Hi, I want to use my iPad mini as a source to play my own backing footage into a TV studio. I'm using Apple's lighting to HDMI converter. When I hook it up to the Blackmagic TV studio it only works if I set the frame rate on the Studio  to 720p at 59

  • I can't send files but i can receive them

    Hello all, I've searched this forum and still need help. My buddy can send me multiple files, while I cannot send him a single one. He gets an error message: "myusername encountered a problem when sending this file" or something euqually as unhelpful

  • Talent Management

    Hello, Scenario: EHP4 - Talent Management  --> Performance management integrated with Compensation Mgmt is it posible to have the budget check to be made, when the manager is entering the final rating for an employee in the appraisal screen. Is that

  • The Window of my Creativ Cloud Desktop App turnd black. So I can't see anything.

    Hey everybody, I have a problem with my Creativ Cloud Desktop App. When I start it first I see the loading icon for about one sek. but the the whole window turns black after that. I've tried to restart the PC or also only the App but that doesn't cha