Wrong index picked

Why did sometimes SAP choose a wrong index for a table?
We were creating reports that takes data from DFKKOP and IST_TDATA tables. These table contains millions of data. E.g. in one month, the table DFKKOP grows from 0 records to 12 millions of records. So index takes very important part here.
We had created additional indexes to improve query performance, but somehow SAP ignores these indexes and use full table scan. We had tried several methods, i.e:
- Fields order in WHERE clause is the same as in the index.
- Using Oracle HINTS INDEX .
- Using Oracle HINTS FIRST_ROWS.
- Update table statistic
- Adjusting the index (SE14)
Sometimes the right index can be chosen by using HINTS INDEX, but sometimes we have to use the FIRST_ROWS hints, and sometimes none can give the right index. In a unique case I have a query with 1-2 records in FOR ALL ENTRIES internal table that SAP can use the right index. But when the internal table in FOR ALL ENTRIES contains 3 or more records,  the same query use full table scan which is extremely slow.
We are using ECC 6 and Oracle 10g.
Please help... Is there notes or fix that I should implement?

About the last unique problem, here is the code:
  data:
    begin of it_vkont occurs 100,
      gpart like fkkvkp-gpart,
      vkont like fkkvkp-vkont,
    end of it_vkont,
    begin of it_object_id occurs 0,
      vkont like ist_tdata-vkont,
      object_id like ist_tdata-object_id,
    end of it_object_id.
* -- for snote contains 3 records, this query will return 3 records 
  select distinct vkont object_id into table it_object_id from ist_tdata
    where object_id in snotel
    %_hints oracle 'FIRST_ROWS'.
  if it_object_id[] is initial.
    message e000(0k) with 'Phone number does not exist'.
    return.
  endif.
* -- for snote contains 3 records, this query will also return 3 records 
  select gpart vkont appending table it_vkont from fkkvkp
    for all entries in it_object_id
    where vkont = it_object_id-vkont.
  if it_vkont[] is initial.
    message e000(0k) with 'Contract Account does not exist'.
    return.
  endif.
* -- for snote contains 3 (or more) records, SAP will choose a wrong index
  select distinct gpart vkont opbel opupk
         bukrs blart waers budat
         bldat betrw hvorg tvorg
  into table t_data
  from dfkkop
  for all entries in it_vkont
  where gpart = it_vkont-gpart
    and faedn in sfaedn
    and waers in swaers
    and applk eq 'T'
    and bukrs eq '1000'
    and augst eq space
    and augbl eq space
    and ( tvorg ne '0500' or tvorg ne '0420' )
    and blart in ('IP', 'IF', 'IN', 'YY')
    %_hints oracle 'INDEX(DFKKOP"Z04")'.
  sort t_data by gpart vkont opbel opupk.
For workaround I have replaced the last query to a bad query performance practice but works pretty well in our case.
  refresh t_data.
  loop at it_vkont.
    select distinct gpart vkont opbel opupk
           bukrs blart waers budat
           bldat betrw hvorg tvorg
    appending table t_data
    from dfkkop
    where gpart = it_vkont-gpart
      and faedn in sfaedn
      and waers in swaers
      and applk eq 'T'
      and bukrs eq '1000'
      and augst eq space
      and augbl eq space
      and ( tvorg ne '0500' or tvorg ne '0420' )
      and blart in ('IP', 'IF', 'IN', 'YY')
      %_hints oracle 'INDEX(DFKKOP"Z04")'.
  endloop.
  sort t_data by gpart vkont opbel opupk.
  delete adjacent duplicates from t_data.
The index Z04 in DFKKOP contains these ordered fields :
    GPART     Business Partner Number
    FAEDN     Due date for net payment
    WAERS     Transaction Currency
    APPLK     Application area
    BUKRS     Company Code
    AUGST     Clearing status
    AUGBL     Clearing Document or Printed Document
    TVORG     Subtransaction for Document Item
    BLART     Document Type

Similar Messages

  • Why is my query using the wrong index?

    Hi SQL Tuning experts....
    I'm running Oracle 11.2.0.2 EE on Solaris 10
    I've just checked my top SQL statements in OEM and drilling down on the top query of the list, I decided to run SQL Advisor on the query.
    Low and behold, it came back with a profile that gives me a 99.9% improvement.
    When I compared the original plan to the new plan the only difference is that the SQL Advisor is using a different index.
    Now, the dumb DBA question: why? why is Oracle picking the wrong index?
    original plan
    SELECT STATEMENT
      COUNT STOPKEY
        VIEW
          SORT ORDER BY STOPKEY          
            TABLE ACCESS BY INDEX ROWID     ARADMIN.T2179          TABLE
              INDEX RANGE SCAN          ARADMIN.T2179_C3     INDEXnew plan...
    SELECT STATEMENT
      COUNT STOPKEY
        VIEW
          SORT ORDER BY STOPKEY          
            TABLE ACCESS BY INDEX ROWID     ARADMIN.T2179               TABLE
              INDEX RANGE SCAN          ARADMIN.T2179_C536870923     INDEXThe stats:
    table has approx. 3.3Mil rows
    table segment is approx. 15G (5G of it is reclaimable space, but probably not related)
    table has fresh stats and indexes have been recently rebuilt
    indexes in this discussion are both b-tree
    the C3 column is number(15) with 2836897 distinct rows
    the C536870923 columns is VARCHAR2(255) with 1080533 distinct values
    Here is the actual query:
         SELECT *
    FROM (
    SELECT T2179.C1,C536871040,C536871037,C536870944,C3,C536870918,C536870919,
    C536870924,C536871048,C536871049,C536871050,C536870926,C536870925,
    C536870916,C4,C536871275,C536871095,C536870913
    FROM T2179
    WHERE ((T2179.C536870923 = :"SYS_B_0") AND (T2179.C3 > :"SYS_B_1")) ORDER BY C1 DESC )
    WHERE ROWNUM <= :"SYS_B_2"Obviously this is a good example of why we should use profiles. :-)
    Edited by: ji li on Feb 14, 2013 1:32 PM
    Sorry... I should have included the plan output
    I'm guessing this has something to do with the cardinality of the data in the columns.

    Dom.... I've already posted most everything. Here are the relevant init params and misc stuff you are asking for.
    NAME                                 TYPE                             VALUE
    object_cache_optimal_size            integer                          102400
    optimizer_capture_sql_plan_baselines boolean                          FALSE
    optimizer_dynamic_sampling           integer                          2
    optimizer_features_enable            string                           11.2.0.2
    optimizer_index_caching              integer                          0
    optimizer_index_cost_adj             integer                          100
    optimizer_mode                       string                           ALL_ROWS
    optimizer_secure_view_merging        boolean                          TRUE
    optimizer_use_invisible_indexes      boolean                          FALSE
    optimizer_use_pending_statistics     boolean                          FALSE
    optimizer_use_sql_plan_baselines     boolean                          TRUE
    plsql_optimize_level                 integer                          2
    db_file_multiblock_read_count        integer                          128
    db_block_size                        integer                          8192
    cursor_sharing                       string                           FORCE
    SNAME                          PNAME                                    PVAL1 PVAL2
    SYSSTATS_INFO                  STATUS                                         COMPLETED
    SYSSTATS_INFO                  DSTART                                         12-04-2012 12:28
    SYSSTATS_INFO                  DSTOP                                          12-04-2012 15:28
    SYSSTATS_INFO                  FLAGS                                        0
    SYSSTATS_MAIN                  CPUSPEEDNW                     2992.2746781116
    SYSSTATS_MAIN                  IOSEEKTIM                                   10
    SYSSTATS_MAIN                  IOTFRSPEED                                4096
    SYSSTATS_MAIN                  SREADTIM                             48027.271
    SYSSTATS_MAIN                  MREADTIM                             37217.102
    SYSSTATS_MAIN                  CPUSPEED                                  2978
    SYSSTATS_MAIN                  MBRC                                         0
    SYSSTATS_MAIN                  MAXTHR                               400782336
    SYSSTATS_MAIN                  SLAVETHR                               1403904
    13 rows selected.
    QL> l
      1  SELECT * FROM (
      2    SELECT
      3    T2179.C1,
      4    C536871040,
      5    C536871037,
      6    C536870944,
      7    C3,
      8    C536870918,
      9    C536870919,
    10    C536870924,
    11    C536871048,
    12    C536871049,
    13    C536871050,
    14    C536870926,
    15    C536870925,
    16    C536870916,
    17    C4,
    18    C536871275,
    19    C536871095,
    20    C536870913
    21    FROM aradmin.T2179
    22    WHERE (
    23     (C536870923 = '300885690')
    24    AND
    25     (C3 > '1360938353')
    26          )
    27    ORDER BY C1 DESC )
    28* WHERE ROWNUM <= 1
    no rows selected
    Elapsed: 00:00:00.01
    Execution Plan
    Plan hash value: 2768254526
    | Id  | Operation                      | Name     | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT               |          |     1 |  2315 |     6  (17)| 00:00:01 |
    |*  1 |  COUNT STOPKEY                 |          |       |       |            |          |
    |   2 |   VIEW                         |          |     1 |  2315 |     6  (17)| 00:00:01 |
    |*  3 |    SORT ORDER BY STOPKEY       |          |     1 |   226 |     6  (17)| 00:00:01 |
    |*  4 |     TABLE ACCESS BY INDEX ROWID| T2179    |     1 |   226 |     5   (0)| 00:00:01 |
    |*  5 |      INDEX RANGE SCAN          | T2179_C3 |     1 |       |     3   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
       1 - filter(ROWNUM<=1)
       3 - filter(ROWNUM<=1)
       4 - filter("C536870923"='300885690')
       5 - access(SYS_OP_DESCEND("C3")<HEXTORAW('3AF1C2A1ABC9FF') )
           filter(SYS_OP_UNDESCEND(SYS_OP_DESCEND("C3"))>1360938353)
    Statistics
              0  recursive calls
              0  db block gets
           2615  consistent gets
              0  physical reads
              0  redo size
           1538  bytes sent via SQL*Net to client
            513  bytes received via SQL*Net from client
              1  SQL*Net roundtrips to/from client
              1  sorts (memory)
              0  sorts (disk)
              0  rows processed

  • Query uses wrong index

    Hi,
    I have exported and imported two schemas to a different server. Now when a user fires a select query it takes more time than before. When I saw the execution plan for some of 'select' queries,I found that the queries are using wrong index.This is the reason for the delayed reponse time.
    Can anybody tell me why it happened ?
    Now what should I do?
    Can I force select query to use the right index?
    Thanx in advance

    Please find below details of the query and indexes. Do let me know if you need more information.
    Query:
    SELECT ROWID, warehouse_code, branch_code, client_code, job_srnum,
    department, inventory_date, file_no, client_carton_no, description,
    ref1, ref2, ref3, destruction_date, subject, pnw_carton_no,
    cre_user_id, cre_dt, upd_user_id, branch, upd_dt, status, date1,
    date2, num1, carton_size, addendum_date
    FROM ISTORET.rmst_inventory_details2
    WHERE branch_code = 'BOM'
    AND job_srnum = '62100113476'
    AND client_carton_no = 'BM4060394822'
    AND subject = 'FILES'
    ORDER BY file_no
    Execution Plan:
    Operation Object Name Rows Bytes Cost
    SELECT STATEMENT Optimizer Mode=CHOOSE 1 15
    SORT ORDER BY 1 155 15
    TABLE ACCESS BY INDEX ROWID ISTORET.RMST_INVENTORY_DETAILS2 1 155 5
    INDEX RANGE SCAN ISTORET.BRC_JOB_SUB_REF123_INDX 1 4
    Query time: More than 5 mins
    Same query with hint /*+ index(rmst_inventory_details2 BRC_JOB_CTN_FILE_INDX) */
    SELECT STATEMENT Optimizer Mode=CHOOSE 1 6
    TABLE ACCESS BY INDEX ROWID ISTORET.RMST_INVENTORY_DETAILS2 1 155 6
    INDEX RANGE SCAN ISTORET.BRC_JOB_CTN_FILE_INDX 1 5
    Query time: 110 msecs
    Index details:
    PARAMETER INDEX- 1 INDEX- 2
    Table Owner ISTORET ISTORET
    Table Name RMST_INVENTORY_DETAILS2 RMST_INVENTORY_DETAILS2
    Index Name BRC_JOB_CTN_FILE_INDX BRC_JOB_SUB_REF123_INDX
    Uniqueness NONUNIQUE NONUNIQUE
    Columns BRANCH_CODE
    JOB_SRNUM
    CLIENT_CARTON_NO
    FILE_NO BRANCH_CODE
    JOB_SRNUM
    SUBJECT
    REF1
    REF2
    REF3
    Table Type TABLE TABLE
    Status VALID VALID
    Tablespace ISTORET_RID2_INDX ISTORET_RID2_INDX
    Initial Extent Size 4,194,304 4,194,304
    Next Extent Size 4,194,304 4,194,304
    Minimum Extents 1 1
    Maximum Extents 2,147,483,645 2,147,483,645
    Percent Increase 0 0
    Distinct Keys 42,576,227 27,318,132
    Percent Free 10 10
    Index Type NORMAL NORMAL
    Partitioned No No
    Temporary No No
    Join Index No No
    Size in MB 2,456 2,140
    Number Extents 614 535
    Size in bytes 2,575,302,656 2,243,952,640
    Last Analyzed 20/3/2007 20/3/2007

  • Secondary Index Picked with one field short in select query

    Hi,
    We have a select query as follows
    select  single lgort       vgbel        vgpos
        into   (lips-lgort,lips-vgbel,lips-vgpos)
        from    lips
       where         vbeln          Eq p_zlcpp-vbeln
         and         matnr          Eq p_zlcpp-matnr
         and         charg          Eq p_zlcpp-charg
    The secondary index ZB has the fields as follows:
    MANDT     Client
    MATNR     Material Number
    CHARG     Batch Number
    BWART     Movement Type (Inventory Management)
    When seen in the trace it seems the select query picks this secondary index. Whether it is correct? since i find no BWART in the select query. Because of this index the query take large time. I used the Hint statement as follows:
    select  single lgort       vgbel        vgpos
        into   (lips-lgort,lips-vgbel,lips-vgpos)
        from    lips
       where         vbeln          Eq p_zlcpp-vbeln
         and         matnr          Eq p_zlcpp-matnr
         and         charg          Eq p_zlcpp-charg   %_HINTS ORACLE 'INDEX("LIPS" "LIPS~0")' .
    and it now works fast. Please advice the best way to make the select query work on itself without using the hint statement to pick the index LIPS~0 instead of the invalid secondary index ZB.
    Thanks & Regards,
    Selvakumar M.
    Edited by: Selva on Jun 17, 2011 7:35 PM

    Hello Selva,
    your problem here is the decision of the optimizer that does not exactly know the selectivity of the fields.
    If your deliveries are normally small (not too many items), then selecting via the document number will be relatively fast.
    And selecting via the material number + batch will be slow in case if many deliveries are having same product from the same batch delivered.
    I assume that the latest is the case in your system. That's why the selection with ZB index is slow.
    If the data distribution is as I described above, then your hint is quite OK and I advise you to stick to the hint.
    From my PoV this is the better solution rather changing the coding and throwing out MATNR field from the WHERE clause to filter later in ABAP.
    Another solution would be trying to play with histograms. But you'll need %SUBSTITUTE VALUES% or %SUBSTITUTE LITERALS% hint anyway, so I find your solution better.
    So, please stay with hint. Even SAP standard development does it for some select statements.
    Regards,
      Yuri

  • Wrong gl picking up in po

    Hi All,
    We have a problem related to wrong picking of gl in po. The account assignement category is "K". Please guide as to where this configutration is done.

    Hi,
    If you are using AAG K  in thsi case you have to enter cost center and GL account manually in Account assignment TAB in PO.
    if system pick wrong GL for Material then Go to OBYC in BSX check the GL account assigned to the valuation class assigned to your material.
    Regards,
    Shayam
    Edited by: Shayam_210 on Aug 11, 2011 1:05 PM

  • S230u wrong driver picked up in SU / thininstal​ler

    I have a s230u and when I run system update it is picking up the wrong wless driver software. this is the one picked up by SU / and thininstaller :
    If you check this thread - this is the one i'm told is the correct driver?
    http://forums.lenovo.com/t5/ThinkPad-Edge-S-series​/S230u-Twist-Windows-7-Intel-wless-driver/m-p/1323​...
    Any way this can be corrrected ?
    Thanks

    susytem Update and Thininstaller are telling me this software is for this machine - when I try to install it it says its not compatible! - I agreee all drivers look to be installed. If so, what is this software, why is it telling me this machine is missing it if I cant install it ?

  • Wrongly Price Picking in Shipment Cost

    Hi Guru’s,
    I am maintaining the condition records for freight cost in Tk11, choose the condition type I have configured for freight and maintain those records for freight basis the truck type and the transporter rate is scale wise. Example- 100km – 3/- & 200km-4/-
    I am creating the shipment in VT01N & selected the two delivers & Route, Route Km is 100. I have created the shipment cost in VI01, system picking the KM is 100 but price picking 4/- instead of 3/-.
    Can anybody give the advice? Why it is pickup wrong price? Is any setting or configuration required?
    Useful answers duly rewarded
    Regards,
    Devendra

    Hi,
    Thanks for reply,
    I have maintained the Scale type in “To scale" but same problem is there.  My client is requirement the fright calculation – KM x Rate x MT(Qty) & rate is scale basis.  I have maintained the condition type as below
    Scale
    Scale basis – R – (Distance)
    Check value -   (None)
    Scale type    -  (To-scale)
    After maintained the condition, I am creating the shipment cost & go to condition. I have checked the header conditions details; system doubles the KM in Scale base val. 200 km instead of 100 km.
    Pl. give the advice
    Regards,
    Devendra
    Pl. help
    Edited by: Devendra on Mar 11, 2008 11:36 AM
    Edited by: Devendra on Mar 17, 2008 6:44 AM

  • Wrong index return from indexOf?

    hi all
    i have a problem with String.indexOf().
    i want to catch all hrefs in a html document. for that I have the html content stored in a string.
    while (context.toUpperCase().indexOf("HREF=\"",i) != -1)
                   String _s;
                   _s = context.substring(context.toUpperCase().indexOf("HREF=\"",i)+6,context.toUpperCase().indexOf("\"",context.toUpperCase().indexOf("HREF=",i)+6));
                   i = context.toUpperCase().indexOf("HREF=\"",i)+4;
    with this code i parse the string.
    it works fine few times.
    register.php
    calender.php
    memberslist.php
    team.php
    search.php
    misc.php
    index.php
    misc.php <--- until here
    egister.php" <-- from here on the first char is cut and at the end is a '"'
    isc.php"
    ndex.php"
    i tested it with several pages.. there was no strange code in the html and it differs in position.
    does someone know something about this?

    yes the Forum translate it strang. I am from Germany and the char I meen is an "sharp s". I've found out now what the Problem is.
    In Germany there is no sign for a UPPER sharp s. so most Programms convert an "sharp s" to SS.
    String s2 = "abc��defg";
    System.out.println(s1.toUpperCase());
    returns :
    ABCSSDEFG
    thats why the index that is returned is at wrong postition because I don't get the substring from the UPPER String.
    thx all 4 help i think i will use the Pattern method know. it is cleaner and there won't be this problem

  • JTable.getSelectedRow seems to return wrong index value in J2SDK 1.4

    OS version: Microsoft Windows 2000 [Version 5.00.2195]
    JDK version: J2RE, Standard Edition (build 1.4.2_07-b05)
    I have a pretty simple JTable in which when a user selects a particular value in the first column of a row, the remainder of the columns in that row are populated with text values. The way we tell the JTable which row to populate the column values for is via the getSelectedRow() method. This worked fine using 1.3.1.08. However, when we upgraded to 1.4.2.07, we get an ArrayIndexOutOfBoundsException thrown because for some reason the getSelectedRow method returns the wrong value (e.g. if the user selects the first row, instead of returning an index of 0, the method returns an index of 2, even if there is only 1 row in the table, thus the out-of-bounds). The code has not changed at all -- all we have done is upgrade the version of the JDK. I have seen similar issues on various postings on the web, but these all have to do with removing rows and the like, and having to cancel or stop cell editing before removing the row(s). However, this does not apply in my case, so I think this might be a new bug. Before I post all kinds of code, does anybody know if this is a known bug and/or is there a workaround?
    Here is my stack trace:
    In Thread[AWT-EventQueue-0,6,main]
    caught java.lang.ArrayIndexOutOfBoundsException: 2 >= 2
         at java.util.Vector.elementAt(Vector.java:431)
         at javax.swing.table.DefaultTableModel.setValueAt(DefaultTableModel.java:633)
         at com.sra.kdd.tools.view.NtwrkDefnVW.propertyChange(NtwrkDefnVW.java:475)
         at java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSupport.java:330)
         at java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSupport.java:257)
         at com.sra.kdd.tools.model.NtwrkSourceDSMDL.setDsNM(NtwrkSourceDSMDL.java:298)
         at com.sra.kdd.tools.view.NtwrkCTRL.handleSourceTableEvent(NtwrkCTRL.java:464)
         at com.sra.kdd.tools.view.NtwrkCTRL.tableChanged(NtwrkCTRL.java:120)
         at javax.swing.table.AbstractTableModel.fireTableChanged(AbstractTableModel.java:280)
         at javax.swing.table.AbstractTableModel.fireTableCellUpdated(AbstractTableModel.java:259)
         at javax.swing.table.DefaultTableModel.setValueAt(DefaultTableModel.java:635)
         at javax.swing.JTable.setValueAt(JTable.java:1794)
         at javax.swing.JTable.editingStopped(JTable.java:3167)
         at javax.swing.AbstractCellEditor.fireEditingStopped(AbstractCellEditor.java:124)
         at javax.swing.DefaultCellEditor$EditorDelegate.stopCellEditing(DefaultCellEditor.java:329)
         at javax.swing.DefaultCellEditor$3.stopCellEditing(DefaultCellEditor.java:139)
         at javax.swing.DefaultCellEditor.stopCellEditing(DefaultCellEditor.java:214)
         at javax.swing.DefaultCellEditor$EditorDelegate.actionPerformed(DefaultCellEditor.java:346)
         at javax.swing.JComboBox.fireActionEvent(JComboBox.java:1197)
         at javax.swing.JComboBox.setSelectedItem(JComboBox.java:561)
         at javax.swing.JComboBox.setSelectedIndex(JComboBox.java:597)
         at javax.swing.plaf.basic.BasicComboPopup$ListMouseHandler.mouseReleased(BasicComboPopup.java:749)
         at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:232)
         at java.awt.Component.processMouseEvent(Component.java:5100)
         at javax.swing.plaf.basic.BasicComboPopup$2.processMouseEvent(BasicComboPopup.java:452)
         at java.awt.Component.processEvent(Component.java:4897)
         at java.awt.Container.processEvent(Container.java:1569)
         at java.awt.Component.dispatchEventImpl(Component.java:3615)
         at java.awt.Container.dispatchEventImpl(Container.java:1627)
         at java.awt.Component.dispatchEvent(Component.java:3477)
         at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:3483)
         at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3198)
         at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3128)
         at java.awt.Container.dispatchEventImpl(Container.java:1613)
         at java.awt.Window.dispatchEventImpl(Window.java:1606)
         at java.awt.Component.dispatchEvent(Component.java:3477)
         at java.awt.EventQueue.dispatchEvent(EventQueue.java:456)
         at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:201)
         at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)
         at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:145)
         at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)
         at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)
    I do have a workaround -- this is definitely not a recommended workaround whatsoever, but it's what I've done just to get by for now, so I thought it might possibly shed some light into the problem. It seems that the index is always off by 2, so I just subtract 2 from the result of getSelectedRow() and then everything works just fine.
    Any ideas? Thank you!

    If I remember correctly there was a big change in the focus subsystem between JDK1.3 and JDK1.4
    Before I post all kinds of code,...Write a 10 line demo program that shows this behaviour. We aren't interested in all kinds of code. If you can't duplicate the problem in 10 lines of code, then the problem is with the rest of your code. So compare you demo code to see why its working and your current code to see why its not working.

  • Wrong index usage in execution plan

    I have one large document in container created with DBXML_INDEX_NODES flag.
    There is an index by "high" attribute node
    self.container.addIndex ( "", "high", "edge-attribute-equality-double", self.uc )
    About 50% of elements in document have structure:
    <record><data high="XX.XX" /></record>
    Which are inside "session" element which is itself inside "log" element. Only one "log" and one "session" element exist in document
    Index by “high” attribute node is very selective. Below is execution plan (changing index to "node" doesn't change things). Index is used on "presence" of "high" attribute and not "value" of it. I think using it for value would improve the speed of the query. Here is the query produced the execution plan below "collection ( 'test.dbxml' )/log/session/record[data/@high=79.37]"
    <XQuery>
    <Navigation>
    <QueryPlanFunction result="collection" container="seasonal.dbxml">
    <OQPlan>P(edge-attribute-equality-double,prefix,data.@high)</OQPlan>
    </QueryPlanFunction>
    <Step axis="child" name="log" nodeType="element"/>
    <Step axis="child" name="session" nodeType="element"/>
    <Step axis="child" name="record" nodeType="element"/>
    <DbXmlFilter>
    <Navigation>
    <Step axis="child" name="data" nodeType="element">
    <OQPlan>P(edge-attribute-equality-double,prefix,data.@high)</OQPlan>
    </Step>
    <Step axis="attribute" name="high" nodeType="attribute"/>
    <DbXmlCompare name="equal">
    <OQPlan>P(edge-attribute-equality-double,prefix,@high)</OQPlan>
    <Sequence>
    <AnyAtomicTypeConstructor value="79.37" typeuri="http://www.w3.org/2001/XMLSchema" typename="decimal"/>
    </Sequence>
    </DbXmlCompare>
    </Navigation>
    </DbXmlFilter>
    </Navigation>
    </XQuery>
    Also, why is the “typename” attribute of “AnyAtomicTypeConstructor” element is “decimal”?
    Removing flag DBXML_INDEX_NODES on the container increases speed significantly and produces this execution plan, speed is not acceptable though.
    <XQuery>
    <Navigation>
    <QueryPlanFunction result="collection" container="seasonal.dbxml">
    <OQPlan>P(edge-attribute-equality-double,prefix,data.@high)</OQPlan>
    </QueryPlanFunction>
    <Step axis="child" name="log" nodeType="element"/>
    <Step axis="child" name="session" nodeType="element"/>
    <Step axis="child" name="record" nodeType="element"/>
    <DbXmlFilter>
    <Navigation>
    <Step axis="child" name="data" nodeType="element"/>
    <Step axis="attribute" name="high" nodeType="attribute"/>
    <DbXmlCompare name="equal">
    <Sequence>
    <AnyAtomicTypeConstructor value="79.37" typeuri="http://www.w3.org/2001/XMLSchema" typename="decimal"/>
    </Sequence>
    </DbXmlCompare>
    </Navigation>
    </DbXmlFilter>
    </Navigation>
    </XQuery>
    Using index lookup allows achieving speed I need. I'd like to know how to properly write the query and what index to use in my case, though.

    Your query is not using the index because the numeric literal you are using is an xs:decimal, not an xs:double. Wrapping your literal in a cast should make the query use your index:
    collection ( 'test.dbxml' )/log/session/record[data/@high=xs:double(79.37)]
    Having said that, this is only the case for DB XML 2.2.13 and before. It turns out that DB XML has been choosing the wrong type to perform comparisons under - and this has been remedied in the forthcoming version. In your case, the new behaviour will mean that the comparison will always be performed as an xs:double.
    John

  • Wrong price picked in purchase order created with reference to RFQ.

    Hi Experts,
    We are encountering an error when we adopt a service RFQ. We maintained 3 RFQs at different prices for 3 different vendors. When we try to adopt the RFQs in the PO, the system picks up the price of the last RFQ maintained. The system gives the same price for whatever RFQ number that we use (for the same item). This goes for service items only (whether with service master record or none). I do not know if this is a customizing setting or a program error.
    Will give points to helpful answers. I would appreciate any input. Thanks!
    Regards,
    M khan

    Hi,
    I have checked in MEKA for all the condition there are no price available for the service.
    I am facing this problem in Services not in material.
    Thanks and regards,
    Munna.

  • Wrong index being chosen-start routine slow

    Hi,
    We are uploading 6Million odd records using lookup and aggregation in the start routine of update rules from an ODS into an infocube.
    One such lookup is on the source ODS itself and takes the longest. The WHERE clause of the SELECT exactly matches one of the secondary indices 020 but is not used when the datapack size is 50,000 but is used only when the datapacksize is a few 100 records. However, the index that does get used in the case of large datapackages  is 030 which only partially matches the fields in the WHERE clause.
    I have tried the following modifications of the SELECT as two alternatives but neither works :
    1) used the Oracle hint INDEX specifically for index 020
    2) removed the FOR ALL ENTRIES IN DATA_PACKAGE clause and used a ranges table for selection in the WHERE clause on certain fields
    The index 020 has been 'Analysed' and statistics have been created.
    Does someone have ideas on why a particular index will not get used in this specific case ?
    Best regards
    Anuradha
    Message was edited by: anuradha govil

    Hi,
    could you post the code ?
    /manfred

  • Using to_date causes CBO to use wrong index

    I'm working on switching an application from using the Rule-based optimizer to use the Cost-based Optimizer on Oracle 9iR2. I'm having problems with the following query:
    select report_rsn, reports.facility_code,
           exams.facility_code
      from exams join reports using (report_rsn)
    where reports.transcribed_date
            between to_date('17-Mar-2005')
                and to_date('18-Mar-2005')
       and exams.dictated_for_rsn = 3323
       and exams.status IN ('S','T')There is an index on the reports.transcribed_date column and a compound index on (exams.dictated_for_rsn,exams.status).
    EXPLAIN PLAN tells me this query will use the transcribed_date as the driving index, but when I run the query through SQL_TRACE, tkprof says that it used the other index instead. That took a long time. (90 seconds)
    If I change the to_date() functions to be ANSI date literals (DATE '2005-03-17' and DATE '2005-03-18'), EXPLAIN PLAN says the same as before, and tkprof says that it actually used that plan. The query returned almost instantly.
    We have CURSOR_SHARING set to 'SIMILAR', and my best guess is that there is something involving the "bind parameter peeking" that is causing the problem. It appears as if the optimizer does not evaluate the to_date() function between "peeking" at the bind variable and determining the execution plan, so it does not know that the two dates are only a day apart. However, I haven't been able to find anything in the docs to confirm my suspicions.
    I've done a search for queries in our system that use the to_date() function as part of the where clause, and it doesn't look like a Herculean task to simply change them all, but I'm wondering two things:
    1) Is there a better way to solve the problem?
    2) Is there any information on this behavior out there that I can read to verify my suspicions? This might be the most important, because in order to finalize the switch to CBO, I need to be able to tell my supervisor that "this sort of thing" won't happen on our production box.
    -- Jeff Beal

    Jeff,
    Could you post your plan under both scenarios? WhatHere are the relevant* (different) portions of the execution plan (as given by TKPROF):
    * I actually ran TKProf against a much larger query, but the controlling part is the query that I included.
    When using DATE literal:
    Rows     Row Source Operation
          0               NESTED LOOPS 
          0                TABLE ACCESS BY INDEX ROWID REPORTS
          6                 INDEX RANGE SCAN IX_REPORTS_TRDATE (object id 109215)
          0                TABLE ACCESS BY INDEX ROWID EXAMS
          0                 INDEX RANGE SCAN IX_FK_EXAMS_11 (object id 96878)When using to_date function
    Rows     Row Source Operation
      46517                NESTED LOOPS 
      46517                 INLIST ITERATOR 
      46517                  TABLE ACCESS BY INDEX ROWID EXAMS
      46517                   INDEX RANGE SCAN IX_FK_EXAMS_4 (object id 139880)
          0                 TABLE ACCESS BY INDEX ROWID REPORTS
      46517                   INDEX UNIQUE SCAN PK_REPORTS (object id 109164)
    are the indexes on the tables and on what columns are
    they present?'ix_fk_exams_4' is a compound index on the exams table.  The first column is 'dictated_for_rsn' and the second is 'status'.  'pk_reports' is an index on reports.report_rsn - the primary key of the table.  'ix_reports_trdate' is on the reports.transcribed_date column.  'ix_fk_exams_11' is on exams.report_rsn (the foreign key to the reports table).
    Just to give you an idea on size, the exams table has about six million rows; the reports table has about 5.5 million.  I would categorize the transcribed_date column as evenly distributed, along with the values in dictated_for_rsn.  The status column is heavily skewed, with 'T' and 'S' being the two most common statuses.

  • Select distinct is using the wrong index

    Hello,
    I have an indexes question?
    I have a table with 1M rows, the table structure is as follows:
    create table X(aTime DATE , a1 NUMBER(28,0), a2 NUMBER(28,0), a3 NUMBER(28,0), .... , a20 NUMBER(28,0) );
    I have also 2 indexes:
    - IDX1 is defined on (aTime, a1, a2, a3).
    - IDX2 is defined on (a1, a2, a3).
    I run the following query: "SELECT DISTINCT A1, A2, A3 from X;" and see that the optimizer chooses to do a FTS (full table scan) though I was expecting him to use IDX2 because it looks like a "covering" indexes giving all the answers to the query without fetching data rows.
    When I try to force him to use indexes, using the following hint "/*+INDEX(X IDX2)*/" the optimizer chooses IDX1.
    When I use same hint after I dropped IDX1 the optimizer still prefers to make FTS .
    Some general info:
    - a1, a2 and a3 have about 500 distinct values each).
    - db version 8.1.7.4.
    - all tables and indexes are analyzed.
    I have two questions:
    ===============
    1.
    Why does the optimizer prefers IDX1 (aTime, a1, a2, a3) over IDX2 (a1, a2, a3) when the query specifically requests distinct values of (aTime, a1, a2, a3), isn't there a shortcut the optimizer should use here?
    2.
    When I request the optimizer to use specific index (using hints), shouldn't it use the index I request regardless of his calculations? If not, is there any way to change this behavior?
    Tal Olier
    [email protected]

    You said you analyzed the tables and indexes. Did you also analyze the indexed columns?
    A full table scan may be a better execution plan than using an index, especially if you are selecting the full table.
    Remember that a hint is jut that, a hint. It suggests to the optimizer to do something, but the optimizer may still choose a different plan.

  • Wrong Indexes being used on Oracle 10.2.0.4

    Hi All
    We have recently performed a combined Unicode and Upgrade from SAP version 4.7 (running Oracle 10.2.0.2) to ERP 6.0 with Enhancement Pack 4 (running Oracle 10.2.0.4).
    During UAT, the users have complained that the performance is slow, (compared to the non-unicode 4.7 system), even though the server the UAT is being done on has double the CPU and memory of the previous 4.7 server (14 CPU and 64GB RAM compared to 6 CPU and 32 GB RAM)
    Along with my basis colleagues, we have found that some of the batch jobs that run, are actually using different indexes compared to the 4.7 system. This is also the case for some processing that is done in the foreground.
    We have run a stats update on the 10.2.0.4 DB in the exact same way that we have on the 10.2.0.2 one, yet the optimizer seems to be choosing a different index, which is impacting our performance.
    Has anybody seen this problem before, and can you advise of a solution.
    Thanks
    Sam

    Hi,
    I have this problem all the time
    Catch the statement in ST04 or if you already have,
    clip it to ST05 and let us have the "explain Plan" output.
    Would be a better base to discuss on.
    Regards
    Volker

Maybe you are looking for

  • How can I run a Module pool program in Background

    Hi all,        I have created report program and called a dialog screen e.g call screen 0100. this screen contains only one table control and a tabstrip control which allows user to select diffrent options.there is a push button on the application to

  • I have no audio when using chrome

    I have no audio when using chrome. I have audio when using Internet explorer and when playing from my pc. I have tried uninstalling chrome and flash player then reinstalling them. have tried FAQ on chromes site and Adobe's site. did not work.

  • Need help --Generating tree

    Hi all, I have a Vector of length 4 in which there are two elements which comes exactly in the order below: A B 1) Name ---------------------------- John 2) Contact -------------------------Country 3) Name-----------------------------David 4) Contact

  • Looking for Download link of oracle 10g for linux PPC (IBM POWER)

    The official download link has been removed in OTN. Looking for show of hands... thanks!

  • Publishing Captivate 5.5

    I imported a ppt into Captivate. Built the presentation.  Now when I publish it there is gray at the bottom of every slide.  I've resized the project, and changed some of the preferences and nothing has corrected the issue.  I've also imported from P