<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Wrong index picked in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/wrong-index-picked/m-p/3419055#M821217</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Agreed. Hints should only be used when all other options to construct a proper select statement were unsuccessful. Since these guys have created their own Z04 index, this might be a case for forcing that index to be used. In my example I have quoted, I had to force the CBO to use BKPF~5 index (CPUDT), because due to an Oracle &lt;DEL&gt;bug&lt;/DEL&gt; feature it would not use this best access path for a particular query. And we have about 100 million records in BKPF.&lt;/P&gt;&lt;P&gt;Cheers&lt;/P&gt;&lt;P&gt;Thomas&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 14 Feb 2008 16:24:07 GMT</pubDate>
    <dc:creator>ThomasZloch</dc:creator>
    <dc:date>2008-02-14T16:24:07Z</dc:date>
    <item>
      <title>Wrong index picked</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/wrong-index-picked/m-p/3419047#M821209</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Why did sometimes SAP choose a wrong index for a table? &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;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:&lt;/P&gt;&lt;P&gt;- Fields order in WHERE clause is the same as in the index.&lt;/P&gt;&lt;P&gt;- Using Oracle HINTS INDEX .&lt;/P&gt;&lt;P&gt;- Using Oracle HINTS FIRST_ROWS.&lt;/P&gt;&lt;P&gt;- Update table statistic&lt;/P&gt;&lt;P&gt;- Adjusting the index (SE14)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;We are using ECC 6 and Oracle 10g.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Please help... Is there notes or fix that I should implement?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 12 Feb 2008 19:37:38 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/wrong-index-picked/m-p/3419047#M821209</guid>
      <dc:creator>adhimassetianeg</dc:creator>
      <dc:date>2008-02-12T19:37:38Z</dc:date>
    </item>
    <item>
      <title>Re: Wrong index picked</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/wrong-index-picked/m-p/3419048#M821210</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Sounds odd for sure - please provide the Open SQL that you are running...  and the code that populates the fields used in the WHERE clause of that SQL.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 12 Feb 2008 19:46:29 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/wrong-index-picked/m-p/3419048#M821210</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-02-12T19:46:29Z</dc:date>
    </item>
    <item>
      <title>Re: Wrong index picked</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/wrong-index-picked/m-p/3419049#M821211</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Well, SAP already has created six secondary indexes for this table. Sometimes adding more indexes, particularly when they are similar to existing ones just confuses the database optimizer into picking the wrong one.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Also, if you are selecting large amounts of data, the database may decide to do a full table scan anyway.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Can we see your SELECT?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Rob&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 12 Feb 2008 19:49:11 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/wrong-index-picked/m-p/3419049#M821211</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-02-12T19:49:11Z</dc:date>
    </item>
    <item>
      <title>Re: Wrong index picked</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/wrong-index-picked/m-p/3419050#M821212</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Adhimas,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Do you have some SQL that we can review?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you have solved your problem on your own, please close this thread.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 13 Feb 2008 22:08:13 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/wrong-index-picked/m-p/3419050#M821212</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-02-13T22:08:13Z</dc:date>
    </item>
    <item>
      <title>Re: Wrong index picked</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/wrong-index-picked/m-p/3419051#M821213</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;About the last unique problem, here is the code:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
  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.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;-&lt;/P&gt;&lt;HR originaltext="----" /&gt;&lt;P&gt;For workaround I have replaced the last query to a bad query performance practice but works pretty well in our case.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
  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.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;-&lt;/P&gt;&lt;HR originaltext="----" /&gt;&lt;P&gt;The index Z04 in DFKKOP contains these ordered fields :&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;    GPART	Business Partner Number&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;    FAEDN	Due date for net payment&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;    WAERS	Transaction Currency&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;    APPLK	Application area&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;    BUKRS	Company Code&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;    AUGST	Clearing status&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;    AUGBL	Clearing Document or Printed Document&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;    TVORG	Subtransaction for Document Item&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;    BLART	Document Type&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 14 Feb 2008 11:21:50 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/wrong-index-picked/m-p/3419051#M821213</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-02-14T11:21:50Z</dc:date>
    </item>
    <item>
      <title>Re: Wrong index picked</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/wrong-index-picked/m-p/3419052#M821214</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Well there a couple of errors in the WHERE, one obvious and the other not so obvious:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;      and ( tvorg ne '0500' or tvorg ne '0420' )&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You probably mean:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;      and ( tvorg ne '0500' and tvorg ne '0420' )&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;And using "NE" for that condition will prevent the SELECT from using that field or any field that follows it in the index.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Maybe this will be better:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;TABLES: dfkkop, tfktvo.

RANGES: r_tvorg FOR dfkkop-tvorg.

* Get all values of tvorg into a range table.

MOVE 'EQ' TO r_tvorg-option.
MOVE 'I'  TO r_tvorg-sign.
SELECT tvorg FROM  tfktvo
  INTO r_tvorg-low.
  APPEND r_tvorg.
ENDSELECT.

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 IN r_tvorg                    "&amp;lt;====
    AND blart IN ('IP', 'IF', 'IN', 'YY').
ENDLOOP.

SORT t_data BY gpart vkont opbel opupk.
DELETE ADJACENT DUPLICATES FROM t_data.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Rob&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 14 Feb 2008 15:14:04 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/wrong-index-picked/m-p/3419052#M821214</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-02-14T15:14:04Z</dc:date>
    </item>
    <item>
      <title>Re: Wrong index picked</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/wrong-index-picked/m-p/3419053#M821215</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;your syntax for the Oracle hints looks odd, I have been using this syntax successfully:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;%_HINTS ORACLE 'INDEX("BKPF" "BKPF~5")'&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;that would translate into&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;%_HINTS ORACLE 'INDEX("DFKKOP" "DFKKOP~Z04")'&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;for your particular case. Maybe worth a try.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Cheers&lt;/P&gt;&lt;P&gt;Thomas&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 14 Feb 2008 15:57:04 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/wrong-index-picked/m-p/3419053#M821215</guid>
      <dc:creator>ThomasZloch</dc:creator>
      <dc:date>2008-02-14T15:57:04Z</dc:date>
    </item>
    <item>
      <title>Re: Wrong index picked</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/wrong-index-picked/m-p/3419054#M821216</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Rather than using HINTS, I think he should see if he can get it to use the proper index without it. That way, if the database statistics change dramatically, it won't be forced into picking the wrong index.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Rob&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 14 Feb 2008 16:17:03 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/wrong-index-picked/m-p/3419054#M821216</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-02-14T16:17:03Z</dc:date>
    </item>
    <item>
      <title>Re: Wrong index picked</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/wrong-index-picked/m-p/3419055#M821217</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Agreed. Hints should only be used when all other options to construct a proper select statement were unsuccessful. Since these guys have created their own Z04 index, this might be a case for forcing that index to be used. In my example I have quoted, I had to force the CBO to use BKPF~5 index (CPUDT), because due to an Oracle &lt;DEL&gt;bug&lt;/DEL&gt; feature it would not use this best access path for a particular query. And we have about 100 million records in BKPF.&lt;/P&gt;&lt;P&gt;Cheers&lt;/P&gt;&lt;P&gt;Thomas&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 14 Feb 2008 16:24:07 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/wrong-index-picked/m-p/3419055#M821217</guid>
      <dc:creator>ThomasZloch</dc:creator>
      <dc:date>2008-02-14T16:24:07Z</dc:date>
    </item>
    <item>
      <title>Re: Wrong index picked</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/wrong-index-picked/m-p/3419056#M821218</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you for all your suggestions. I have tried changing the NE to using a IN just as your example in another case with no success in finding the right INDEX. But I'll try again for this case and I will also try changing the syntax for HINTS.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I will let you know the results by monday because today I'm not in the office.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 15 Feb 2008 08:17:30 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/wrong-index-picked/m-p/3419056#M821218</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-02-15T08:17:30Z</dc:date>
    </item>
    <item>
      <title>Re: Wrong index picked</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/wrong-index-picked/m-p/3419057#M821219</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I haven't tried the suggestions but during sap notes search I found this interesting article that I think I should share with you all. The note number is &lt;STRONG&gt;176754&lt;/STRONG&gt;.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;-adhimas-&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 17 Feb 2008 10:33:55 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/wrong-index-picked/m-p/3419057#M821219</guid>
      <dc:creator>adhimassetianeg</dc:creator>
      <dc:date>2008-02-17T10:33:55Z</dc:date>
    </item>
  </channel>
</rss>

