<?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: Poor performance reading MBEWH table in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/poor-performance-reading-mbewh-table/m-p/5915986#M1330628</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&amp;gt; any index is used, &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;there is no any index, either an index is used, then it has a name or no index.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can see the index only in the ST05, with the function DB-explain&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;A secondary index can be as good as the primary index!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The data of th other clients are irrelvant you will not see and not search them.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 13 Jul 2009 15:10:23 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2009-07-13T15:10:23Z</dc:date>
    <item>
      <title>Poor performance reading MBEWH table</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/poor-performance-reading-mbewh-table/m-p/5915979#M1330621</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm getting serious performance problems when reading MBEWH table directly.&lt;/P&gt;&lt;P&gt;I did the following tests:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
  GET RUN TIME FIELD t1.
  SELECT mara~matnr
    FROM mara
    INNER JOIN mbewh ON mbewh~matnr = mara~matnr
    INTO TABLE gt_mbewh
    WHERE mbewh~lfgja = '2009'.
  GET RUN TIME FIELD t2.

  GET RUN TIME FIELD t3.
  SELECT mbewh~matnr
    FROM mbewh
    INTO TABLE gt_mbewh
    WHERE mbewh~lfgja = '2009'.
  GET RUN TIME FIELD t4.

t2 = t2 - t1.
t4 = t4 - t3.
write: 'With join: ', t2.
write /.
write: 'Without join: ', t4.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;And as result I got:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
With join:      27.166
Without join:  103970.297
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;All MATNR in MBEWH are in MARA.&lt;/P&gt;&lt;P&gt;MBEWH has 71.745 records and MARA has 705 records.&lt;/P&gt;&lt;P&gt;I created an index for lfgja field in MBEWH.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Why I have better performance using inner join?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In production client, MBEW has 68 million records, so any selection takes too much time.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks in advance,&lt;/P&gt;&lt;P&gt;Frisoni&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Jul 2009 21:13:50 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/poor-performance-reading-mbewh-table/m-p/5915979#M1330621</guid>
      <dc:creator>guilherme_frisoni</dc:creator>
      <dc:date>2009-07-10T21:13:50Z</dc:date>
    </item>
    <item>
      <title>Re: Poor performance reading MBEWH table</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/poor-performance-reading-mbewh-table/m-p/5915980#M1330622</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Guilherme,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Check what happen if you do this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;  SELECT mbewh~matnr
    FROM mbewh
    INNER JOIN mbewh ON mara~matnr = mbewh~matnr
    INTO TABLE gt_mbewh
    WHERE mbewh~lfgja = '2009'.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards, Fernando Da Ró&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Jul 2009 21:21:17 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/poor-performance-reading-mbewh-table/m-p/5915980#M1330622</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-07-10T21:21:17Z</dc:date>
    </item>
    <item>
      <title>Re: Poor performance reading MBEWH table</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/poor-performance-reading-mbewh-table/m-p/5915981#M1330623</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Fernando,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
  GET RUN TIME FIELD t3.
    SELECT m1~matnr
    FROM mbewh as m1
    INNER JOIN mbewh as m2 ON m2~matnr = m1~matnr
    INTO TABLE gt_mbewh
    WHERE m1~lfgja = '2009'.
  GET RUN TIME FIELD t4.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Result:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
Without join:  259346.845
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Not so good. &lt;span class="lia-unicode-emoji" title=":confused_face:"&gt;😕&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Frisoni&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Jul 2009 21:29:20 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/poor-performance-reading-mbewh-table/m-p/5915981#M1330623</guid>
      <dc:creator>guilherme_frisoni</dc:creator>
      <dc:date>2009-07-10T21:29:20Z</dc:date>
    </item>
    <item>
      <title>Re: Poor performance reading MBEWH table</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/poor-performance-reading-mbewh-table/m-p/5915982#M1330624</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Even worst... &lt;SPAN __jive_emoticon_name="sad"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Perhaps, your database is taking some strange decision when accessing the data.&lt;/P&gt;&lt;P&gt;First, using [ST05|https://www.sdn.sap.com/irj/scn/weblogs?blog=/pub/wlg/7205] &lt;B&gt;[original link is broken]&lt;/B&gt; &lt;B&gt;[original link is broken]&lt;/B&gt; &lt;B&gt;[original link is broken]&lt;/B&gt;; check the execution plan.&lt;/P&gt;&lt;P&gt;My guess is that your database statistics aren't updated (check it on DB20 for each table), and share your impressions with us.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;OPS... I'm sorry Guilherme I made a mistake, I "read" that without join was better than join... Anyway, the execution plan gathered on ST05 will solve your doubt.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards, Fernando Da Ru00F3s&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edited by: Fernando Ros on Jul 10, 2009 11:35 PM&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Jul 2009 21:33:01 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/poor-performance-reading-mbewh-table/m-p/5915982#M1330624</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-07-10T21:33:01Z</dc:date>
    </item>
    <item>
      <title>Re: Poor performance reading MBEWH table</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/poor-performance-reading-mbewh-table/m-p/5915983#M1330625</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;if you look at the table MATNR BWKEY BWTAR LFGJA LFMON are the primary keys... the more primary keys u can use more performance can be improved... try to work on it...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;for more easier test : se30 &amp;gt; tips and tricks button..&lt;/P&gt;&lt;P&gt;write your two codes side by side and hit  Measure runtime...&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Jul 2009 21:37:56 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/poor-performance-reading-mbewh-table/m-p/5915983#M1330625</guid>
      <dc:creator>former_member156446</dc:creator>
      <dc:date>2009-07-10T21:37:56Z</dc:date>
    </item>
    <item>
      <title>Re: Poor performance reading MBEWH table</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/poor-performance-reading-mbewh-table/m-p/5915984#M1330626</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;your measurment comes for a test system, with this totals for the tables??&lt;/P&gt;&lt;P&gt;&amp;gt; MBEWH has 71.745 records and MARA has 705 records.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;... if yes, what is the question?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;With this setup the bahavior is o.k.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But does it help for your production system? Not at all. How many records are in MARA in the production system?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;How records will come back?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Maybe archiving could be a godd starting point.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Otherwise, please add ST05 information to such questions!!!!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Siegfried&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Jul 2009 15:54:14 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/poor-performance-reading-mbewh-table/m-p/5915984#M1330626</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-07-11T15:54:14Z</dc:date>
    </item>
    <item>
      <title>Re: Poor performance reading MBEWH table</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/poor-performance-reading-mbewh-table/m-p/5915985#M1330627</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I just found that besides the current client has just 80000 records, there are two hidden clients in the same server with 50 million rocords.&lt;/P&gt;&lt;P&gt;Checking ST05, when I run SELECT just with MBEWH, any index is used, even after I created an Index in the where field.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But when using a JOIN with MARA, the primary index is used and performance is much better.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Frisoni&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 13 Jul 2009 14:41:19 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/poor-performance-reading-mbewh-table/m-p/5915985#M1330627</guid>
      <dc:creator>guilherme_frisoni</dc:creator>
      <dc:date>2009-07-13T14:41:19Z</dc:date>
    </item>
    <item>
      <title>Re: Poor performance reading MBEWH table</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/poor-performance-reading-mbewh-table/m-p/5915986#M1330628</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&amp;gt; any index is used, &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;there is no any index, either an index is used, then it has a name or no index.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can see the index only in the ST05, with the function DB-explain&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;A secondary index can be as good as the primary index!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The data of th other clients are irrelvant you will not see and not search them.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 13 Jul 2009 15:10:23 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/poor-performance-reading-mbewh-table/m-p/5915986#M1330628</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-07-13T15:10:23Z</dc:date>
    </item>
    <item>
      <title>Re: Poor performance reading MBEWH table</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/poor-performance-reading-mbewh-table/m-p/5915987#M1330629</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ST05 execution plans are below. In same order as the code posted before.&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
SELECT STATEMENT ( Estimated Costs = 51.113 , Estimated #Rows = 555.197 )

       3 NESTED LOOPS
         ( Estim. Costs = 51.113 , Estim. #Rows = 555.197 )
         Estim. CPU-Costs = 1.091.447.843 Estim. IO-Costs = 51.021

           1 INDEX FAST FULL SCAN MARA~0
             ( Estim. Costs = 48 , Estim. #Rows = 7.282 )
             Estim. CPU-Costs = 9.706.161 Estim. IO-Costs = 47
             Filter Predicates
           2 INDEX RANGE SCAN MBEWH~0
             ( Estim. Costs = 7 , Estim. #Rows = 76 )
             Search Columns: 3
             Estim. CPU-Costs = 148.550 Estim. IO-Costs = 7
             Access Predicates Filter Predicates
&lt;/CODE&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;CODE&gt;
SELECT STATEMENT ( Estimated Costs = 76.169 , Estimated #Rows = 1.768.067 )

       1 TABLE ACCESS FULL MBEWH
         ( Estim. Costs = 76.169 , Estim. #Rows = 1.768.067 )
         Estim. CPU-Costs = 19.049.481.694 Estim. IO-Costs = 74.562
         Filter Predicates
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I created the following index:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
NONUNIQUE  Index   MBEWH~Z01

Column Name                     #Distinct

LFGJA                                          5
MANDT                                          6
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Why this index is not used, and a full scan is made?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Frisoni&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 13 Jul 2009 16:17:11 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/poor-performance-reading-mbewh-table/m-p/5915987#M1330629</guid>
      <dc:creator>guilherme_frisoni</dc:creator>
      <dc:date>2009-07-13T16:17:11Z</dc:date>
    </item>
    <item>
      <title>Re: Poor performance reading MBEWH table</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/poor-performance-reading-mbewh-table/m-p/5915988#M1330630</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Add Mandt on ur select statement &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  SELECT mbewh~matnr&lt;/P&gt;&lt;P&gt;    FROM mbewh&lt;/P&gt;&lt;P&gt;    INTO TABLE gt_mbewh&lt;/P&gt;&lt;P&gt;    WHERE mbewh~lfgja = '2009'&lt;/P&gt;&lt;P&gt;and mandt = sy-mandt.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 13 Jul 2009 17:38:01 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/poor-performance-reading-mbewh-table/m-p/5915988#M1330630</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-07-13T17:38:01Z</dc:date>
    </item>
    <item>
      <title>Re: Poor performance reading MBEWH table</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/poor-performance-reading-mbewh-table/m-p/5915989#M1330631</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Frisoni,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;your first examle reads all records (keys) of a small table (MARA) in the most efficient way possible (index fast full scan),&lt;/P&gt;&lt;P&gt;and joins these small number of lines to a big table where for each line a range scan with quite selective fields (MATNR) is done.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;for your second example:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;gt; &lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;gt; Why this index is not used, and a full scan is made?&lt;/P&gt;&lt;P&gt;&amp;gt;&lt;/P&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;From all the different figures in your post, i don't get how much records your MBEWH table has. However, the optimizer&lt;/P&gt;&lt;P&gt;makes the following assumption:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;estimated nr. of records = ( nr of table rows / nr of clients (6) / nr of LFGJA (5) )&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;so estimated nr. of records = (nr. of table rows / 30 )&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;A quite unselective index range scan has to be performed. That is probably not as efficient as one full table scan.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Reccomendation for THIS example:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Add the MATNR field to your index and the optimizer will probaly swich from a full table scan to a (fast)full index scan.&lt;/P&gt;&lt;P&gt;But that might still be slower than your join, since your join starts on MARA (few records) and access MBWEH only a few times for the few records. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For your index design you have to use the figures from your productive systems...&lt;/P&gt;&lt;P&gt;nr. of clients in production, nr. of records in MARA and MBWEH how much records fullfil your condition   WHERE mbewh~lfgja = '2009' on MBWEH.... with this information one can come up with a recommendation for production...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Kind regards,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hermann&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 14 Jul 2009 07:00:42 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/poor-performance-reading-mbewh-table/m-p/5915989#M1330631</guid>
      <dc:creator>HermannGahm</dc:creator>
      <dc:date>2009-07-14T07:00:42Z</dc:date>
    </item>
    <item>
      <title>Re: Poor performance reading MBEWH table</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/poor-performance-reading-mbewh-table/m-p/5915990#M1330632</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I don't understand what you expect from your index!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Go to this explain   TABLE ACCESS FULL MBEWH&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Doubleclick on the tablename MBEWH&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;=&amp;gt; what do the statistics show?&lt;/P&gt;&lt;P&gt;How many records are in the table,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Scroll down what indexes do you see, is there your Z01 index, does it have statistics data?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If no, it can not be used.&lt;/P&gt;&lt;P&gt;If yes, what is the number of distinct values of lfgja.   It can hardly be larger than 10.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Siegfried&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 14 Jul 2009 07:38:15 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/poor-performance-reading-mbewh-table/m-p/5915990#M1330632</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-07-14T07:38:15Z</dc:date>
    </item>
    <item>
      <title>Re: Poor performance reading MBEWH table</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/poor-performance-reading-mbewh-table/m-p/5915991#M1330633</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Siegfried,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;the index statistics in MBEWH are as following:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
NONUNIQUE  Index   MBEWH~Z01

Column Name                     #Distinct

LFGJA                                          5
MANDT                                          6

Last statistics date                  10.07.2009
Analyze Method               Sample 531.679 Rows
Levels of B-Tree                               3
Number of leaf blocks                    148.100
Number of distinct keys                       12
Average leaf blocks per key               12.341
Average data blocks per key              171.933
Clustering factor                      2.063.200
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I can't understand why this index is not used, or what I have to to to create an index by LFGJA.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Frisoni&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 14 Jul 2009 14:15:10 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/poor-performance-reading-mbewh-table/m-p/5915991#M1330633</guid>
      <dc:creator>guilherme_frisoni</dc:creator>
      <dc:date>2009-07-14T14:15:10Z</dc:date>
    </item>
    <item>
      <title>Re: Poor performance reading MBEWH table</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/poor-performance-reading-mbewh-table/m-p/5915992#M1330634</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;the optimizer uses these figures to calculate the cost for your range scan:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;gt; Levels of B-Tree                               3&lt;/P&gt;&lt;P&gt;&amp;gt; Number of distinct keys                       12&lt;/P&gt;&lt;P&gt;&amp;gt; Average leaf blocks per key               12.341&lt;/P&gt;&lt;P&gt;&amp;gt; Average data blocks per key              171.933&lt;/P&gt;&lt;P&gt;&amp;gt; Clustering factor                      2.063.200&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;the resulting cost is higher than the cost for a full table scan.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;therefore it chooses a full table scan.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For cost comparison the table statistics are missing.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;you can try to enforce the index usage:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%_hints oracle("MBEWH~Z01" "MBWEH") &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;but it will probaly be not faster... (depending on your datadistribution).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;in case of unequal data distribution a hint (but not the index hint, rather substitute values and histograms)&lt;/P&gt;&lt;P&gt;could make sense.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Kind regards,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hermann&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 14 Jul 2009 14:24:49 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/poor-performance-reading-mbewh-table/m-p/5915992#M1330634</guid>
      <dc:creator>HermannGahm</dc:creator>
      <dc:date>2009-07-14T14:24:49Z</dc:date>
    </item>
    <item>
      <title>Re: Poor performance reading MBEWH table</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/poor-performance-reading-mbewh-table/m-p/5915993#M1330635</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Hermann,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I forced to use Z01 index with &lt;STRONG&gt;%_hints oracle 'INDEX(MBEWH "MBEWH~Z01")'&lt;/STRONG&gt;, and got a much better result for without join statement:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
With join:      96.217
Without join:      93.781
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The execution plan was that:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
SELECT STATEMENT ( Estimated Costs = 184.550 , Estimated #Rows = 1.768.067 )

       2 TABLE ACCESS BY INDEX ROWID MBEWH
         ( Estim. Costs = 184.550 , Estim. #Rows = 1.768.067 )
         Estim. CPU-Costs = 3.217.515.212 Estim. IO-Costs = 184.279

           1 INDEX RANGE SCAN MBEWH~Z01
             ( Estim. Costs = 12.427 , Estim. #Rows = 4.420.167 )
             Search Columns: 2
             Estim. CPU-Costs = 974.045.977 Estim. IO-Costs = 12.345
             Access Predicates
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now i'm going to test this results in production.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Frisoni&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 14 Jul 2009 15:10:20 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/poor-performance-reading-mbewh-table/m-p/5915993#M1330635</guid>
      <dc:creator>guilherme_frisoni</dc:creator>
      <dc:date>2009-07-14T15:10:20Z</dc:date>
    </item>
    <item>
      <title>Re: Poor performance reading MBEWH table</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/poor-performance-reading-mbewh-table/m-p/5915994#M1330636</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Frisoni,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;gt; &lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;gt; I forced to use Z01 index with &lt;STRONG&gt;%_hints oracle 'INDEX(MBEWH "MBEWH~Z01")'&lt;/STRONG&gt;, and got a much better result for without join statement:&lt;/P&gt;&lt;P&gt;&amp;gt; &amp;gt; With join:      96.217&lt;/P&gt;&lt;P&gt;&amp;gt; &amp;gt; Without join:      93.781&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;that doesnt sound &lt;STRONG&gt;MUCH better&lt;/STRONG&gt;... more or less equal... &lt;SPAN __jive_emoticon_name="wink"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;However &lt;STRONG&gt;BE CAREFULL&lt;/STRONG&gt; with forcing index usage if your data distribution is not equal&lt;/P&gt;&lt;P&gt;and your where conditions are changing (different values) you can easily get results&lt;/P&gt;&lt;P&gt;which are &lt;STRONG&gt;MUCH worse&lt;/STRONG&gt; than the original full table scan.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Analyze your data distribution and your queries (WHERE conditions) on your production system... &lt;STRONG&gt;THEN&lt;/STRONG&gt; think about&lt;/P&gt;&lt;P&gt;how to optimize your accesses...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Kind regards,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hermann&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 14 Jul 2009 15:23:03 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/poor-performance-reading-mbewh-table/m-p/5915994#M1330636</guid>
      <dc:creator>HermannGahm</dc:creator>
      <dc:date>2009-07-14T15:23:03Z</dc:date>
    </item>
    <item>
      <title>Re: Poor performance reading MBEWH table</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/poor-performance-reading-mbewh-table/m-p/5915995#M1330637</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Frisoni,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;as said the estimated cost for the fts is lower:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;

SELECT STATEMENT ( Estimated Costs = 76.169 , Estimated #Rows = 1.768.067 ) 
       1 TABLE ACCESS FULL MBEWH
       ...

SELECT STATEMENT ( Estimated Costs = 184.550 , Estimated #Rows = 1.768.067 )
 ...
       2 TABLE ACCESS BY INDEX ROWID MBEWH
...
           1 INDEX RANGE SCAN MBEWH~Z01
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;the reason why it runs faster is probably the uneven data distribution. So, again,&lt;/P&gt;&lt;P&gt;be carefull with forcing index usage when you access the data with different &lt;/P&gt;&lt;P&gt;variables for mandt and lfgja.. .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;and btw... &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;for this query:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SELECT mbewh~matnr&lt;/P&gt;&lt;P&gt;    FROM mbewh&lt;/P&gt;&lt;P&gt;    INTO TABLE gt_mbewh&lt;/P&gt;&lt;P&gt;    WHERE mbewh~lfgja = '2009'.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;you could try with an index with an index on  MANDT, LFGJA, MATNR.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Then there is NO table access required anymore. Therfore the optimizer may choose&lt;/P&gt;&lt;P&gt;it without a hint since it is a covering index. And the optimizer can go for a&lt;/P&gt;&lt;P&gt;index fast full scan, which is faster than an index range scan (what you have&lt;/P&gt;&lt;P&gt;currently with the index hint).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;and&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Kind reards,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hermann&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 14 Jul 2009 15:49:38 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/poor-performance-reading-mbewh-table/m-p/5915995#M1330637</guid>
      <dc:creator>HermannGahm</dc:creator>
      <dc:date>2009-07-14T15:49:38Z</dc:date>
    </item>
    <item>
      <title>Re: Poor performance reading MBEWH table</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/poor-performance-reading-mbewh-table/m-p/5915996#M1330638</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&amp;gt; With join:      96.217&lt;/P&gt;&lt;P&gt;&amp;gt; Without join:      93.781&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;before downtime I wanted to write that this is equal, repeat measurement and it might change.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The costs show the opposite as Hermann pointed out.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So if there is a runtime difference, then is depends on the actual distribution of the data in the different years compared to the equal distribution which the optimizer assumes.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;One field with 5 different vaules can not really help to get fast access,&lt;/P&gt;&lt;P&gt;only if you search for the value which is very rare much lower than 10%.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you system has  the last 5 years of data, then this years has still less than 1/5 of data, but hopefully after 6 six months already&lt;/P&gt;&lt;P&gt;much more 1/10 = 10% ( &amp;gt; 5% - 10% is the value where the full table scan becomes better) &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Siegfried&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 14 Jul 2009 16:16:17 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/poor-performance-reading-mbewh-table/m-p/5915996#M1330638</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-07-14T16:16:17Z</dc:date>
    </item>
    <item>
      <title>Re: Poor performance reading MBEWH table</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/poor-performance-reading-mbewh-table/m-p/5915997#M1330639</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Guilherme, Hermann, Siegfried,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have just seen this thread and read it from top to bottom, and I would say now is a good time to make a summary.. &lt;SPAN __jive_emoticon_name="happy"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;This is want I got from Guilherme's comments:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1) MBEWH has 71.745 records &lt;/P&gt;&lt;P&gt;2) There are two hidden clients in the same server with 50 million rocords.&lt;/P&gt;&lt;P&gt;3) Count Distinct mandt = 6&lt;/P&gt;&lt;P&gt;4) In production client, MBEW has 68 million records&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;First measurement&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;With join               : 27.166&lt;/P&gt;&lt;P&gt;Without join            :  103970.297&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Second measurement &lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;With join               : 96.217&lt;/P&gt;&lt;P&gt;Without join            : 93.781            &amp;lt;&amp;lt; now with hint&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The original question was to understand why using the JOIN made the query much faster.&lt;/P&gt;&lt;P&gt;So the conclusions are:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1) Execution times are really now much better (comparing only the &lt;EM&gt;not&lt;/EM&gt; using join case, which is the one we are working on), and the original "mystery" is gone&lt;/P&gt;&lt;P&gt;2) In this client, MANDT is actually much more selective that the optimizer thinks it is (and it's because of this uneven distrubution, as Hermann mentioned, that forcing the index made such a difference)&lt;/P&gt;&lt;P&gt;4) Bad news is that this solution was good because of the special case of your development system, but will probably not help in the production system&lt;/P&gt;&lt;P&gt;5) I suppose the index that Hermann suggested is the best possible thing to do (the table won't be read, assuming you really only want only MATNR from MBEWH, and that it wasn't a simplification for illustration purposes); anyway, noone can really expect that getting all entries from MBEWH for a given year will be a fast thing...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Rui Dantas&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 14 Jul 2009 16:50:06 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/poor-performance-reading-mbewh-table/m-p/5915997#M1330639</guid>
      <dc:creator>Rui_Dantas</dc:creator>
      <dc:date>2009-07-14T16:50:06Z</dc:date>
    </item>
    <item>
      <title>Re: Poor performance reading MBEWH table</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/poor-performance-reading-mbewh-table/m-p/5915998#M1330640</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi again,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;after some tests in production, i'm writing the results:&lt;/P&gt;&lt;P&gt;MBEWH has 68.466.116 records, all in the same MANDT.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The select statement is as follow:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
    SELECT matnr
           bwkey
           lfgja
           lfmon
           SUM( lbkum )
           SUM( salk3 )
      FROM mbewh
      INTO TABLE gt_mbewh
      WHERE lfgja = '2009'
        AND bwtar NE space
      GROUP BY matnr
               bwkey
               lfgja
               lfmon
      %_HINTS ORACLE 'INDEX(MBEWH "MBEWH~Z01")'.   *Used in case 2 only
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Z01 index is updated:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
MANDT                                          1
LFGJA                                          5

Last statistics date                  14.07.2009
Analyze Method              mple 68.466.122 Rows
Levels of B-Tree                               3
Number of leaf blocks                    190.714
Number of distinct keys                        5
Average leaf blocks per key               38.142
Average data blocks per key              375.429
Clustering factor                      1.877.145
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;-&lt;/P&gt;&lt;HR originaltext="----" /&gt;&lt;P&gt;Case 1, withou use Z01 index:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
SELECT STATEMENT ( Estimated Costs = 211.498 , Estimated #Rows = 11.737.048 )

       2 HASH GROUP BY
         ( Estim. Costs = 211.498 , Estim. #Rows = 11.737.048 )
         Estim. CPU-Costs = 40.495.510.483 Estim. IO-Costs = 208.081

           1 TABLE ACCESS FULL MBEWH
             ( Estim. Costs = 95.980 , Estim. #Rows = 11.737.048 )
             Estim. CPU-Costs = 25.870.861.489 Estim. IO-Costs = 93.797
             Filter Predicates
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Time to execute: 139.392.371&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 14 Jul 2009 18:55:49 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/poor-performance-reading-mbewh-table/m-p/5915998#M1330640</guid>
      <dc:creator>guilherme_frisoni</dc:creator>
      <dc:date>2009-07-14T18:55:49Z</dc:date>
    </item>
  </channel>
</rss>

