<?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: Expensive SQL due to huge data selected in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/expensive-sql-due-to-huge-data-selected/m-p/6661802#M1446422</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;200.000 records ... is a lot, is this really necessary???&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The FAE will take a while, the recommendation with the RANGES is nonsense, it will dump!!!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If it would not dump, the reduction of the WHERE condition would easily lead to 1.000.000 to be transferred.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So pleae think twice before giving recommendations!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 12 Mar 2010 10:28:14 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2010-03-12T10:28:14Z</dc:date>
    <item>
      <title>Expensive SQL due to huge data selected</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/expensive-sql-due-to-huge-data-selected/m-p/6661799#M1446419</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi experts,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;There is an expensive select query in my report. From the trace, I can see it nearly take 9 minutes or so to run.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SELECT MBLNR&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;         MJAHR&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;         ZEILE&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;         INTO TABLE FP_IT_MSEG&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;         FROM MSEG&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;         FOR ALL ENTRIES IN FP_IT_S031&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;         WHERE MATNR EQ FP_IT_S031-MATNR&lt;/P&gt;&lt;P&gt; AND&lt;/P&gt;&lt;P&gt;               WERKS EQ FP_IT_S031-WERKS&lt;/P&gt;&lt;P&gt; AND&lt;/P&gt;&lt;P&gt;               LGORT EQ FP_IT_S031-LGORT.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;And about 205206 records of the 7838904 records will be selected to table FP_IT_MSEG which is declared as standard table.   Although it matched an secondary index, it still took that much time.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;How should I optimize it? Will it speed up if using package size(such 500) ? Should I declared table FP_IT_S031 with more initial size(like 300000) ?    Or do you think I should split it into several same select statement with smaller size FP_IT_S031.?&lt;/P&gt;&lt;P&gt;  &lt;/P&gt;&lt;P&gt;If you faced similar issues, do let me know? I can only test it after moving to Q.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks &amp;amp; Regards..&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 11 Mar 2010 03:39:53 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/expensive-sql-due-to-huge-data-selected/m-p/6661799#M1446419</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2010-03-11T03:39:53Z</dc:date>
    </item>
    <item>
      <title>Re: Expensive SQL due to huge data selected</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/expensive-sql-due-to-huge-data-selected/m-p/6661800#M1446420</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;you are selecting large amount of data and using FOR ALL ENTRIES - system generates new query for each row in FP_IT_S031 table.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You could try to:&lt;/P&gt;&lt;P&gt;- descrease size of FP_IT_S031 table (this might not meet your requirements) - how many rows does it have in average?&lt;/P&gt;&lt;P&gt;- you could try to create RANGES for material, and select more data from database, &lt;/P&gt;&lt;P&gt;    and than filter them and remove unnecessary - but you have to check if it works for you (it depends on how many different&lt;/P&gt;&lt;P&gt;    materials you have, how many plants and storage locations, etc.).&lt;/P&gt;&lt;P&gt;    Changed code would look like:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
// prepare RA_MATNR based on FP_IT_S031
...

// select data
SELECT mblnr mjahr zeile matnr werks lgort
  INTO TABLE fp_it_mseg[]
  FROM mseg
  WHERE matnr IN ra_matnr[].

// filter data
LOOP AT fp_it_mseg.      // better use ASSIGNING here
  READ TABLE fp_it_s031[]
    WITH TABLE KEY matnr = fp_it_mseg-matnr
                   werks = fp_it_mseg-werks
                   lgort = fp_it_mseg-lgort
    TRANSPORTING NO FIELDS.
  IF sy-subrc NE 0.
    DELETE fp_it_mseg.
  ENDIF.
ENDLOOP.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;&lt;P&gt;Although it matched an secondary index, it still took that much time.&lt;/P&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;You are matching index, but FOR ALL ENTRIES generate series of queries, which takes long time&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;--&lt;/P&gt;&lt;P&gt;Przemysław&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 11 Mar 2010 10:03:13 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/expensive-sql-due-to-huge-data-selected/m-p/6661800#M1446420</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2010-03-11T10:03:13Z</dc:date>
    </item>
    <item>
      <title>Re: Expensive SQL due to huge data selected</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/expensive-sql-due-to-huge-data-selected/m-p/6661801#M1446421</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;ok, let's see:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;9 minutes (or so) for 205206 is 0.002632  seconds (2.6 milli seconds) per record (or so)&lt;/P&gt;&lt;P&gt;That is not too shabby &lt;SPAN __jive_emoticon_name="wink"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;double check that there are no duplicates in the internal table FP_IT_S031.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What database are you running on?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Dependent on the database you are running on there might be a few options&lt;/P&gt;&lt;P&gt;to improve it &lt;STRONG&gt;a little bit&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;e.g. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;increase the blocking factor for FAE with a hint will do less round trips&lt;/P&gt;&lt;P&gt;and could improve the performance a little bit.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;a rather drastic option would be to create the ideal index (add field form select to the used index(&lt;/P&gt;&lt;P&gt;in order to get an index only access but that is probably too much... &lt;SPAN __jive_emoticon_name="wink"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Once again, your response time is already quite good there is not much room for&lt;/P&gt;&lt;P&gt;improvement with an FAE.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Another option to check:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;where do the records in internal table FP_IT_S031 come from? if they come straight out&lt;/P&gt;&lt;P&gt;of a database table avoid the FAE and use a join. Here you could probably gain more.&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>Thu, 11 Mar 2010 20:50:05 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/expensive-sql-due-to-huge-data-selected/m-p/6661801#M1446421</guid>
      <dc:creator>HermannGahm</dc:creator>
      <dc:date>2010-03-11T20:50:05Z</dc:date>
    </item>
    <item>
      <title>Re: Expensive SQL due to huge data selected</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/expensive-sql-due-to-huge-data-selected/m-p/6661802#M1446422</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;200.000 records ... is a lot, is this really necessary???&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The FAE will take a while, the recommendation with the RANGES is nonsense, it will dump!!!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If it would not dump, the reduction of the WHERE condition would easily lead to 1.000.000 to be transferred.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So pleae think twice before giving recommendations!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 12 Mar 2010 10:28:14 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/expensive-sql-due-to-huge-data-selected/m-p/6661802#M1446422</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2010-03-12T10:28:14Z</dc:date>
    </item>
  </channel>
</rss>

