Why optimizer select plan with higher cost?

Why optimizer select plan with higher cost?
SQL with hint:
SELECT /*+ index(ordm ORDA_PK) */
ordm.orders_id h_docid, ordm.customer_nr h_clientid,
ordm.cl_doc_type_code h_doctype,
ordm.cl_doc_status_code cl_doc_status_code,
ordm.cl_external_error_code h_errorcode, ordm.sys_version_id h_version,
ordm.doc_number po_number, ordm.curdate po_curdate,
ordm.cl_currency_code po_curr,
TO_CHAR (ordm.amount, 'FM999999999999990.00') po_amount,
ordm.account_nr po_cust_accnum, ordm.customer_name po_cust_name,
ordd.cl_currency_cust_code po_cust_curr,
TO_CHAR (ordd.cust_rate, 'FM999999999990.0099999999') po_cust_rate,
ordd.cust_confirm po_cust_conf, ordd.ben_name po_ben_name,
ordd.ben_accnum po_ben_accnum,
ordd.cl_external_payment_code po_cust_amk, ordd.ben_info po_ben_info,
ordd.comments po_comments
FROM FINIX_IB.orders_archive ordm, FINIX_IB.orders_archive_fields ordd
WHERE ordm.orders_id = ordd.orders_id (+)
AND ordm.orders_id = NVL (4353, ordm.orders_id)
Execution Plan
0 SELECT STATEMENT Optimizer=ALL_ROWS (Cost=4918 Card=1 Bytes=185)
1 0 NESTED LOOPS (OUTER) (Cost=4918 Card=1 Bytes=185)
2 1 TABLE ACCESS (BY INDEX ROWID) OF 'ORDERS_ARCHIVE' (TABLE) (Cost=4916 Card=1 Bytes=87)
3 2 INDEX (FULL SCAN) OF 'ORDA_PK' (INDEX (UNIQUE)) (Cost=4915 Card=1)
4 1 TABLE ACCESS (BY INDEX ROWID) OF 'ORDERS_ARCHIVE_FIELDS' (TABLE) (Cost=2 Card=1 Bytes=98)
5 4 INDEX (RANGE SCAN) OF 'ORDAF_ORDA_FK' (INDEX) (Cost=1 Card=1)
Statistics
0 recursive calls
0 db block gets
4792 consistent gets
4786 physical reads
0 redo size
1020 bytes sent via SQL*Net to client
237 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
1 rows processed
SQL without hint:
Execution Plan
0 SELECT STATEMENT Optimizer=ALL_ROWS (Cost=9675 Card=1 Bytes=185)
1 0 NESTED LOOPS (OUTER) (Cost=9675 Card=1 Bytes=185)
2 1 TABLE ACCESS (FULL) OF 'ORDERS_ARCHIVE' (TABLE) (Cost=9673 Card=1 Bytes=87)
3 1 TABLE ACCESS (BY INDEX ROWID) OF 'ORDERS_ARCHIVE_FIELDS' (TABLE) (Cost=2 Card=1 Bytes=98)
4 3 INDEX (RANGE SCAN) OF 'ORDAF_ORDA_FK' (INDEX) (Cost=1 Card=1)
Statistics
1 recursive calls
0 db block gets
39706 consistent gets
39694 physical reads
0 redo size
1037 bytes sent via SQL*Net to client
237 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
1 rows processed

The way you are comparing costs, is not the right way, as Billy already told you. Only for one query, the cost of different access paths can be compared, as can be seen in a 10053 trace.
However, your problem seems to arise from the fact that you use the NVL function in the predicate "ordm.orders_id = NVL (4353, ordm.orders_id)". The NVL function always evaluates both expressions, so it has to do a "ordm.orders_id = 4353" and a "ordm.orders_id = ordm.orders_id". This is why both alternatives will show a full scan on your orders_archive table cq. orda_pk index.
You are probably suppling a bind variable to this statement which in some cases contains a null and in some other cases contains a number. If by any chance you always supply a number, then the solution is easy: drop the NVL function and change the predicate to "ordm.orders_id = :<your bind variable>". If not, then you have combined two queries into one, where both variants each have its own optimal plan, but they have to share their plan due to bind variable peeking.
To solve this, I think you have two options:
1) Make sure your statement is reparsed everytime. If your statement doesn't get executed often, this strategy might work. You might implement this by doing unnecessary dynamic sql.
2) Split your query into two queries where one handles the constant number input and the other handles the null/no input.
Below are some test results I used for research:
SQL> create table orders_archive
  2  as
  3  select l orders_id, lpad('*',100,'*') filler from (select level l from dual connect by level <= 10000)
  4  /
Tabel is aangemaakt.
SQL> create table orders_archive_fields
  2  as
  3  select l field_id, l+500 orders_id, lpad('*',100,'*') filler from (select level l from dual connect by level <= 9000)
  4  /
Tabel is aangemaakt.
SQL> alter table orders_archive add constraint orda_pk primary key (orders_id)
  2  /
Tabel is gewijzigd.
SQL> alter table orders_archive_fields add constraint ordaf_pk primary key (field_id)
  2  /
Tabel is gewijzigd.
SQL> alter table orders_archive_fields add constraint ordaf_orda_fk foreign key (orders_id) references orders_archive(orders_id)
  2  /
Tabel is gewijzigd.
SQL> create index ordaf_orda_fk on orders_archive_fields(orders_id)
  2  /
Index is aangemaakt.
SQL> exec dbms_stats.gather_table_stats(user,'ORDERS_ARCHIVE',cascade=>true)
PL/SQL-procedure is geslaagd.
SQL> exec dbms_stats.gather_table_stats(user,'ORDERS_ARCHIVE_FIELDS',cascade=>true)
PL/SQL-procedure is geslaagd.
SQL> explain plan
  2  for
  3  SELECT /*+ index(ordm ORDA_PK) */
  4  ordm.orders_id h_docid, ordm.filler, ordd.filler
  5  FROM orders_archive ordm, orders_archive_fields ordd
  6  WHERE ordm.orders_id = ordd.orders_id (+)
  7  AND ordm.orders_id = NVL(4353,ordm.orders_id)
  8  /
Uitleg is gegeven.
SQL> select * from table(dbms_xplan.display)
  2  /
PLAN_TABLE_OUTPUT
| Id  | Operation                    |  Name                  | Rows  | Bytes | Cost (%CPU)|
|   0 | SELECT STATEMENT             |                        |     1 |   209 |     8   (0)|
|   1 |  NESTED LOOPS OUTER          |                        |     1 |   209 |     8   (0)|
|   2 |   TABLE ACCESS BY INDEX ROWID| ORDERS_ARCHIVE         |     1 |   104 |     7   (0)|
|*  3 |    INDEX FULL SCAN           | ORDA_PK                |     1 |       |    22   (5)|
|   4 |   TABLE ACCESS BY INDEX ROWID| ORDERS_ARCHIVE_FIELDS  |     1 |   105 |     2  (50)|
|*  5 |    INDEX RANGE SCAN          | ORDAF_ORDA_FK          |     1 |       |            |
Predicate Information (identified by operation id):
   3 - filter("ORDM"."ORDERS_ID"=NVL(4353,"ORDM"."ORDERS_ID"))
   5 - access("ORDM"."ORDERS_ID"="ORDD"."ORDERS_ID"(+))
17 rijen zijn geselecteerd.
SQL> exec dbms_lock.sleep(1)
PL/SQL-procedure is geslaagd.
SQL> explain plan
  2  for
  3  SELECT
  4  ordm.orders_id h_docid, ordm.filler, ordd.filler
  5  FROM orders_archive ordm, orders_archive_fields ordd
  6  WHERE ordm.orders_id = ordd.orders_id (+)
  7  AND ordm.orders_id = NVL(4353,ordm.orders_id)
  8  /
Uitleg is gegeven.
SQL> select * from table(dbms_xplan.display)
  2  /
PLAN_TABLE_OUTPUT
| Id  | Operation                    |  Name                  | Rows  | Bytes | Cost (%CPU)|
|   0 | SELECT STATEMENT             |                        |     1 |   209 |    47   (7)|
|   1 |  NESTED LOOPS OUTER          |                        |     1 |   209 |    47   (7)|
|*  2 |   TABLE ACCESS FULL          | ORDERS_ARCHIVE         |     1 |   104 |    46   (7)|
|   3 |   TABLE ACCESS BY INDEX ROWID| ORDERS_ARCHIVE_FIELDS  |     1 |   105 |     2  (50)|
|*  4 |    INDEX RANGE SCAN          | ORDAF_ORDA_FK          |     1 |       |            |
Predicate Information (identified by operation id):
   2 - filter("ORDM"."ORDERS_ID"=NVL(4353,"ORDM"."ORDERS_ID"))
   4 - access("ORDM"."ORDERS_ID"="ORDD"."ORDERS_ID"(+))
16 rijen zijn geselecteerd.So this shows I reproduced your situation. Because the decode function doesn't evaluate all its arguments, but evaluates the first argument to see which arguments to evaluate, you'll see different behaviour now.
SQL> exec dbms_lock.sleep(1)
PL/SQL-procedure is geslaagd.
SQL> explain plan
  2  for
  3  SELECT
  4  ordm.orders_id h_docid, ordm.filler, ordd.filler
  5  FROM orders_archive ordm, orders_archive_fields ordd
  6  WHERE ordm.orders_id = ordd.orders_id (+)
  7  AND ordm.orders_id = decode(4353,null,ordm.orders_id,4353)
  8  /
Uitleg is gegeven.
SQL> select * from table(dbms_xplan.display)
  2  /
PLAN_TABLE_OUTPUT
| Id  | Operation                    |  Name                  | Rows  | Bytes | Cost (%CPU)|
|   0 | SELECT STATEMENT             |                        |     1 |   209 |     3  (34)|
|   1 |  NESTED LOOPS OUTER          |                        |     1 |   209 |     3  (34)|
|   2 |   TABLE ACCESS BY INDEX ROWID| ORDERS_ARCHIVE         |     1 |   104 |     2  (50)|
|*  3 |    INDEX UNIQUE SCAN         | ORDA_PK                |     1 |       |     2  (50)|
|   4 |   TABLE ACCESS BY INDEX ROWID| ORDERS_ARCHIVE_FIELDS  |     1 |   105 |     2  (50)|
|*  5 |    INDEX RANGE SCAN          | ORDAF_ORDA_FK          |     1 |       |            |
Predicate Information (identified by operation id):
   3 - access("ORDM"."ORDERS_ID"=4353)
   5 - access("ORDM"."ORDERS_ID"="ORDD"."ORDERS_ID"(+))
17 rijen zijn geselecteerd.
SQL> exec dbms_lock.sleep(1)
PL/SQL-procedure is geslaagd.
SQL> explain plan
  2  for
  3  SELECT
  4  ordm.orders_id h_docid, ordm.filler, ordd.filler
  5  FROM orders_archive ordm, orders_archive_fields ordd
  6  WHERE ordm.orders_id = ordd.orders_id (+)
  7  AND ordm.orders_id = decode(null,null,ordm.orders_id,null)
  8  /
Uitleg is gegeven.
SQL> select * from table(dbms_xplan.display)
  2  /
PLAN_TABLE_OUTPUT
| Id  | Operation                    |  Name                  | Rows  | Bytes | Cost (%CPU)|
|   0 | SELECT STATEMENT             |                        |     1 |   209 |    46   (5)|
|   1 |  NESTED LOOPS OUTER          |                        |     1 |   209 |    46   (5)|
|*  2 |   TABLE ACCESS FULL          | ORDERS_ARCHIVE         |     1 |   104 |    45   (5)|
|   3 |   TABLE ACCESS BY INDEX ROWID| ORDERS_ARCHIVE_FIELDS  |     1 |   105 |     2  (50)|
|*  4 |    INDEX RANGE SCAN          | ORDAF_ORDA_FK          |     1 |       |            |
Predicate Information (identified by operation id):
   2 - filter("ORDM"."ORDERS_ID"="ORDM"."ORDERS_ID")
   4 - access("ORDM"."ORDERS_ID"="ORDD"."ORDERS_ID"(+))
16 rijen zijn geselecteerd.So two different plans depending on the input.
Regards,
Rob.

Similar Messages

  • Advertise OSPF with higher cost

    hi all,
    I need to implement following scenario and i really need your help in this regard.
    My active path toward Branch Office should be via 'CORE ACTIVE' and 'WAN Edge Actve'.
    In case of 'WAN Edge Acive ' failure , I need to traverse that traffic through 'WAN Edge Backup'.
    I used AS path prepend to implement this in BGP Configuration.
    I want to Advertise OSPF routes with higher cost from 'Core Backup'
    1) How should I do this ?
    2) Is there any other better alternate solution which I can use ?
    Thanks a lot for your time and consideration.

    Hello Harshaabba,
    In the past, this is how I have accomplished this in similar situations.
    Under the OSPF config, something similar to this.
     distance 15 8.8.8.8 0.0.0.0 99
    access-list 99 permit 10.5.0.0 0.0.0.255
    access-list 99 permit 10.6.0.0 0.0.0.255
    (15) = AD
    8.8.8.8 = OSPF Router ID
    0.0.0.0 = wildcard bits
    99 = Access list to match
    Note: This isn't always the best solution, but after looking at your diagram, this should work just fine.

  • Transportation planning with shipment costs

    Hello,
    We are using a transportation type that it's relevant for shipment costs. However, we would like that some itineraries wasn't cost relevant. Is it possible or we need to have different transportation types? One relevant and another not relevant?
    Thanks,
    Sónia Gusmã

    Sonia,
          maybe you could use the field "ROUTE" in the tables of the access sequencies so that you enter values only for the relevant routes (itineraries).
    This could be a problem if you have many routes...
    Best regards,
    Paulo Café

  • Execution plan with bind variable

    dear all
    I join two tables and get "index fast full scan" with high cost using bind variable
    but when I remove the bind variable it executes with "index" and with lower cost
    What is the reason and how should I know which execution plan is really used in real life?
    thanks
    john

    1) What is oracle version?
    2) Post here both query and their explain plan.
    In fact INDEX FAST FULL SCAN indicate is multiblock read for composite indexes(and based on your query and predicates).In this case CBO behavior as FULL TABLE SCAN(affected by db_multiblock_read_count,system stats,etc).And you use bind variable.So in bind variable case CBO define selectivity based on arithmetic(5% of the cardinality) ,if you use concrete values instead of bind variable CBO identify other selectivity based on statistics,histograms,.... then it was identify cost of multiblock read and single block reads.You can see these 10053 event.Finally it choose lower cost`s plan.

  • Planned vs Actual Cost Report (with variance) for PM Orders

    Hi Experts,
    We are using the project system to collate order costs for annual shut work.  We have a requirement for a report to show 25% variance between planned and actual order costs (maintneance order).
    At this stage, we dont mind whether this is implemented in the the PM system, or the PS system.
    This is a fairly basic / common requirment.  Are there any standard transactions we could use to:
    1.  Select a list of orders using standard selection criteria.
    2.  Select a % for variance, e.g. 25%
    3.  Display a list of orders where the planned vs actual costs were greater than 25% and what the actual variance is for each order?
    Thanks,
    Maikel

    Hi Maikel,
                   I have never seen any such scenario, but the best thing that can come to me is for the shut down activities you muct have created a Revision, then based on that Revision you can take a dump of all the orders with Planned and Actual Cost, in the excel, and there by putting the formulae you can definitely have the Varience report.
    Hope it helps you.
    Regards,
    Yawar Khan

  • PP/DS Optimizer u2013 Planning for HALB and FERT in sequence with Optimizer

    We are using PP/DS optimizer to plan the two level BOM items. FERT and HALB planned orders are converted from SNP. ROH products are not planned in APO. PPDS is not used to create or delete orders. Only scheduling is done by optimizer. Only one mode exists in PDS. Setup matrix is used for both HALB and FERT.
    The requirement is to schedule HALB products in time on their own resources in time for multiple FERT orders. The optimizer does not appear to do this consistently. We use the following steps in planning run:
    1.     Stage numbering.
    2.     Schedule orders at the earliest with infinite planning. This is done to ensure there are no blank spaces at the beginning of the planning interval on resources after optimization. The result is all orders starting at the same time with multiple loading on resources.
    3.     Optimization with weightage for makespan and setup time. Key settings are: Forward planning, finite resource loading, pegging relevance, considering inter order relationships. All HALB and FERT resources are selected in this step. (Delays are not important within the Optimization interval and there are no stocks of HALB except when there are time gaps between HALB Orders and FERT orders. HALB order is finished earier than FERT order start.)
    The question is: Is Optimizer capable of scheduling HALB and FERT on their own resources  but at the right iner order timings while optimizing the setup time. Are there any key setting to watch out for in Optimization profile or Strategy profile to enable this?
    If this is not possible, we will have optimize only at one BOM level and then use top down or bottom up heuristics to plan the other level.

    HI TemYogi,
    Assumptions:
    1. One PDS each for HALB & FERT level with one resource
    2. HALB to be scheduled first. Based on HALB schedule, FERT has to be scheduled
    To achieve this
    Maintain "Maximum Lateness of a Receipt"  in Pegging tab in Demand tab in Product master
    in FERT PDS maintain the consumption type of HALB components as continious/ start/end of the the operation
    use the planning direction as backward and reverse in DS strategy profile
    Use schedule mode as Insert operation / insert operation and close gaps until end in DS strategy profile
    Fix all the previous run orders in DS board for HALB and then Schedule all the HALB orders considering u r setups through optimization
    Now run the optimizer for FERT
    Regards
    Sravan maturu
    +91 9392602314

  • Key Pad Problem with my Curve 8520 & the HIGH COST of owning a BB

    I used to keenly watch RIM and its progress and how it created a niche for itself and how it started successfully fighting the goliaths who were entering into this niche. 
    This love culminated in me buying a Curve 8520  through Airtel, my GSM service provider against the wishes of my wife. I paid a huge (per my standards) Rupees (Rs) 12500 for the instrument.
    This Monday, while I was responding to a text message I realised that 2 of the keys ( R & H)  are not responding. I thought this is a temporary glitch and I switched off and switched on to realise that this has not changed. Added to the problem was that the faulty key is part of the PIN and the device cannot be activated.
    I contacted my service provider who quoted  Rs 7000 for repairing the key. Since I am maintaining a strict diet and a healthy lifestyle I did not get a cardiac arrest though I could feel a numbness in my head when I heard the estimate.
    When I told the person on the other side of the phone that this is unfair...He also agreed and said that many customers have complained about the high cost of ownership and that RIM might reduce their prices in Jan 2012.. But I can't hold on without using the instrument till jan 2012
    Now I remember that my car (Ford Fiesta) was also bought during the same month as my BB phone. Let me confess that I have not spend even Rs 3000 on maintaining that car so far despite me driving  80 kilometers 5 days a week..
    My Request:
    Sorry for the rambling...Coming to my request.
    I cannot afford to spend Rs 7000 for a repair and I expect RIM to do this free (why should key pad of a carefully used phone fail in 14 months) or a maximum of Rs 500. While I love the features and by now I am sort of addicted to this pet of mine, I am also practical enough to realise that I should not spend out of my means.....So I will have to switch back to a normal phone....
    Is there any other way out ?
    Regards
    Rajesh
    Chennai, India

    OK, it may not be a powered USB socket on the PC. You will need to check you have the right driver. One way to check the connection is in the settings in the BB under memory there is a mass storage mode support which needs ot be on and the auto enable mass storage mode when enabled when connected. This will usually allow you to see the BB like a external hard drive or camera in windows explorer when you connect it.
    If that fails check in the PC device manager for an appropriate device with a problem - usually has a yellow exclamation mark next to it

  • Can't figure out why colors don't totally change when you select type with curser? It looks like it has by looking at it, but when you highlight the area after the old color is still there. It happens with objects to. Driving me NUTZ. Help!

    Can't figure out why colors don't totally change when you select type with curser? It looks like it has by looking at it, but when you highlight the area after the old color is still there. It happens with objects to. Driving me NUTZ. Help!

    Select the text, and open the Appearance palette (Come on guys, text highlight is irrelevant, it happens to objects too says the OP), and see what's listed there.  For a simple text object, there should only be a line item "Type", followed by "Characters", and when double-clicked the Characters line item expands to tell you the stroke and fill color.  For a basic object, there should be a fill and/or stroke.
    What happens sometimes, is that you end up adding extra strokes/fills to objects or text, and the appearance palette is where that will be noted.  Especially when you are dealing with groups, and/or picking up a color with the eyedropper, you may inadvertently be adding a fill or stroke on top of something.  You can drag those unwanted thingies from the Appearance palette into its own little trash can.

  • Select data from database tables with high performance

    hi all,
    how to select data from different database tables with high performance.
    im using for all entries instead of inner joins, even though burden on data base tables is going very high ( 90 % in se30)
    hw to increase the performance.
    kindly, reply.
    thnks

    Also Check you are not using open sql much like distict order by group by , use abap techniques on internal table to acive the same.
    also Dont use select endselect.
    if possible use up to n rows claus....
    taht will limit the data base hits.
    also dont run select in siode any loops.
    i guess these are some of the trics oyu can use to avoid frequent DATA BASE HITS AND ABVOID THE DATA BASE LAOD.

  • Cost Center Integrated Planning with GP12N

    We are using the New GL in 6.0.  I have made all of the Integrated Planning settings in the versions for both the GL Planning and the Cost Center Planning.  If I load the Cost Center Planning through KP06, the transfer works fine.  However, it was my understanding that you could load Cost Center Planning through GP12N, and see it in Cost Center reporting.  This does not seem to work.  Am I missing some particular setting?  We are loading into FAGLFLEXT.
    Thank you for any suggestions.

    Hi,
    - this is not going to happen; cost centre planning is flowing from CO to FI and not viceversa. the same apply if you run a cost centre allocation in accouting: it is not posting to CO.
    - you can use FI planning for accounts not managed as cost element and cost centre planning for the others.
    - as an alternative you can design cost centre reporting in accouting with transaction FGI0.
    Paolo

  • Easy cost planning with integrated planning

    Hi All,
    I am testing easy cost planning and I see that to use easy cost planning, I have to unmark the flag for "Integrated PLanning", this leeds to no creation of line items in planification. Does anyone know if there is a way to use easy cost planning with integrated planning?
    Thanks a lot in advance.

    it may be with reference to the Versions.

  • List of Selected Set with Inspection Plan

    Hi Friends,
    We have assigned a selected set with a number of MIC in different Inspection plan.
    Now, we want to see what are the inspection plan to which  a particular selected set has been assigned
    Pl give any idea through  which we can see it.
    Thanks and Regards,
    SADAN

    Hi,
    You can use PLMK table & create query using SQVI transaction as generally table level access not given in production client.
    Sanjay

  • I have a 2GB data plan with my iphone 5c.  If I purchase a new tablet can I use the phone as a personal hotspot for the tablet without any additional costs?

    I have a 2GB data plan with my iphone 5c.  If I purchase a new tablet can I use the phone as a personal hotspot for the tablet without any additional costs

        dianneb, great question and thanks for the help Weth. The good news is if you're on More Everything the mobile hotspot would be apart of your plan just as Weth mentioned. What you just want to keep in mind is that the usage from the tablet while connected to the hotspot would take from your current plan allowance. Hope this helps!
    AdamG_VZW
    Follow us on Twitter @VZWSupport

  • Why does iPhoto shuts down when I select Info with an image selected.

    Why does iPhoto shut down when I select Info with an image selected.

    Back up your iPhoto library, Depress and hold the option (alt) and command keys and launch iPhoto - rebuild your iPhoto library database
    LN

  • Product costing with components purchased in countries with high inflation

    Hi guru,
    I have the following problem. My company produced in Italy but buy some component from India, that is a country with high inflation.
    When I run the product costing for a finished product in Italy, in which way I can consider the high inflation in India? My doubt is that I can have a wrong product costing because the value of component is not correct
    Thanks
    Regards
    Raffaele

    Hi
    Product costing allows recursive BOM with certain restrictions. Kindly check the following link for more information on recursiveness:
    http://help.sap.com/saphelp_erp2005vp/helpdata/en/bc/566916eff011d189be0000e8214595/frameset.htm
    Regards,
    Suraj

Maybe you are looking for