<?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: Rewrite SQL query to improve performance in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/rewrite-sql-query-to-improve-performance/m-p/4832753#M1130626</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&amp;gt; It is not suggestable to use join on more than 2 tables.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;that is simply nonsense!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
WHERE a~vkorg IN so_vkorg
AND a~vtweg IN so_vtweg
AND a~vkbur IN so_vkbur
AND a~auart IN so_auart
AND a~vbeln IN so_vbeln
AND b~abgru IN so_abgru
AND c~faksk IN so_faksk
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;First you must understand the idea behind ranges.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Your statements will never use all ranges together, that nearly never the case =&amp;gt; there are different&lt;/P&gt;&lt;P&gt;combinations, some are well supported by indexes, some probably not.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;FOR ALL ENTRIES need also indexes, they can not automatically solve your problem. A well-defined&lt;/P&gt;&lt;P&gt;join is faster than a FAE even for more than 2 tables.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Siegfried&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 08 Dec 2008 07:43:47 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2008-12-08T07:43:47Z</dc:date>
    <item>
      <title>Rewrite SQL query to improve performance</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/rewrite-sql-query-to-improve-performance/m-p/4832746#M1130619</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;The below queries are very time consuming.Could you please suggest how to improve performance for these 2 queries:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;QUERY1:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SELECT a&lt;SUB&gt;vbeln a&lt;/SUB&gt;posnr a&lt;SUB&gt;auart a&lt;/SUB&gt;vkorg a&lt;SUB&gt;vtweg a&lt;/SUB&gt;spart&lt;/P&gt;&lt;P&gt;a&lt;SUB&gt;vkbur a&lt;/SUB&gt;kunnr b&lt;SUB&gt;matnr b&lt;/SUB&gt;kwmeng b~vrkme&lt;/P&gt;&lt;P&gt; b&lt;SUB&gt;netwr b&lt;/SUB&gt;werks b&lt;SUB&gt;lgort b&lt;/SUB&gt;vstel b&lt;SUB&gt;abgru b&lt;/SUB&gt;erdat b~ernam&lt;/P&gt;&lt;P&gt;c&lt;SUB&gt;faksk c&lt;/SUB&gt;ktext c&lt;SUB&gt;vdatu c&lt;/SUB&gt;zzbrsch c&lt;SUB&gt;kvgr1 c&lt;/SUB&gt;augru&lt;/P&gt;&lt;P&gt;INTO CORRESPONDING FIELDS OF TABLE g_t_sodata&lt;/P&gt;&lt;P&gt;            FROM vapma AS a INNER JOIN vbap AS b ON&lt;/P&gt;&lt;P&gt;            a&lt;SUB&gt;vbeln = b&lt;/SUB&gt;vbeln AND a&lt;SUB&gt;posnr = b&lt;/SUB&gt;posnr&lt;/P&gt;&lt;P&gt;            INNER JOIN vbak AS c ON a&lt;SUB&gt;vbeln = c&lt;/SUB&gt;vbeln&lt;/P&gt;&lt;P&gt;              WHERE a~vkorg IN so_vkorg&lt;/P&gt;&lt;P&gt;              AND a~vtweg IN so_vtweg&lt;/P&gt;&lt;P&gt;              AND a~vkbur IN so_vkbur&lt;/P&gt;&lt;P&gt;              AND a~auart IN so_auart&lt;/P&gt;&lt;P&gt;              AND a~vbeln IN so_vbeln&lt;/P&gt;&lt;P&gt;              AND b~abgru IN so_abgru&lt;/P&gt;&lt;P&gt;              AND c~faksk IN so_faksk&lt;/P&gt;&lt;P&gt;              AND ( b~erdat GT g_f_zenkai_date OR&lt;/P&gt;&lt;P&gt;        ( b&lt;SUB&gt;erdat EQ g_f_zenkai_date AND b&lt;/SUB&gt;erzet GE g_f_zenkai_time ) )&lt;/P&gt;&lt;P&gt;        AND ( b~erdat LT g_f_kaisi_date  OR&lt;/P&gt;&lt;P&gt;         ( b&lt;SUB&gt;erdat EQ g_f_kaisi_date  AND b&lt;/SUB&gt;erzet LT g_f_kaisi_time ) ).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;QUERY2:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SELECT a&lt;SUB&gt;vbeln a&lt;/SUB&gt;posnr a&lt;SUB&gt;auart a&lt;/SUB&gt;vkorg a&lt;SUB&gt;vtweg a&lt;/SUB&gt;spart&lt;/P&gt;&lt;P&gt;        a&lt;SUB&gt;vkbur a&lt;/SUB&gt;kunnr b&lt;SUB&gt;matnr b&lt;/SUB&gt;kwmeng  b~vrkme&lt;/P&gt;&lt;P&gt;        b~netwr&lt;/P&gt;&lt;P&gt;        b&lt;SUB&gt;werks b&lt;/SUB&gt;lgort b&lt;SUB&gt;vstel b&lt;/SUB&gt;abgru b&lt;SUB&gt;erdat b&lt;/SUB&gt;ernam&lt;/P&gt;&lt;P&gt;        c&lt;SUB&gt;faksk c&lt;/SUB&gt;ktext c&lt;SUB&gt;vdatu c&lt;/SUB&gt;zzbrsch c&lt;SUB&gt;kvgr1 c&lt;/SUB&gt;augru&lt;/P&gt;&lt;P&gt;        INTO CORRESPONDING FIELDS OF TABLE g_t_sodata&lt;/P&gt;&lt;P&gt;       FROM vapma AS a INNER JOIN vbap AS b ON&lt;/P&gt;&lt;P&gt;       a&lt;SUB&gt;vbeln = b&lt;/SUB&gt;vbeln AND a&lt;SUB&gt;posnr = b&lt;/SUB&gt;posnr&lt;/P&gt;&lt;P&gt;       INNER JOIN vbak AS c ON a&lt;SUB&gt;vbeln = c&lt;/SUB&gt;vbeln&lt;/P&gt;&lt;P&gt;         WHERE a~vkorg IN so_vkorg&lt;/P&gt;&lt;P&gt;         AND a~vtweg IN so_vtweg&lt;/P&gt;&lt;P&gt;         AND a~vkbur IN so_vkbur&lt;/P&gt;&lt;P&gt;         AND a~auart IN so_auart&lt;/P&gt;&lt;P&gt;         AND a~vbeln IN so_vbeln&lt;/P&gt;&lt;P&gt;         AND b~abgru IN so_abgru&lt;/P&gt;&lt;P&gt;         AND c~faksk IN so_faksk.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 04 Dec 2008 05:59:59 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/rewrite-sql-query-to-improve-performance/m-p/4832746#M1130619</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-12-04T05:59:59Z</dc:date>
    </item>
    <item>
      <title>Re: Rewrite SQL query to improve performance</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/rewrite-sql-query-to-improve-performance/m-p/4832747#M1130620</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;HI tips,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope these threads will help u on this,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A class="jive_macro jive_macro_thread" href="https://community.sap.com/" __jive_macro_name="thread" modifiedtitle="true" __default_attr="1090584"&gt;&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;A class="jive_macro jive_macro_thread" href="https://community.sap.com/" __jive_macro_name="thread" modifiedtitle="true" __default_attr="919187"&gt;&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regard's,&lt;/P&gt;&lt;P&gt;Lokesh N B&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 04 Dec 2008 06:26:07 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/rewrite-sql-query-to-improve-performance/m-p/4832747#M1130620</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-12-04T06:26:07Z</dc:date>
    </item>
    <item>
      <title>Re: Rewrite SQL query to improve performance</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/rewrite-sql-query-to-improve-performance/m-p/4832748#M1130621</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Questions like this a one of the favorites here in this forum.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I guess that the statements are o.k. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;The problem is the usage!&lt;/STRONG&gt;  There are so many Ranges, if they are filled then some index should support it. If no range is filled then it is usually slow, you can not do anything.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You must find out, which are actually used and under which conditions it is slow and when it is o.k.&lt;/P&gt;&lt;P&gt;Ask again, when you can provide the actual cases.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Use SQL trace to check the performance:&lt;/P&gt;&lt;P&gt;SQL trace:&lt;/P&gt;&lt;P&gt;&lt;A class="jive_macro jive_macro_blogpost" href="https://community.sap.com/" __jive_macro_name="blogpost" modifiedtitle="true" __default_attr="44587"&gt;&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I know the probabilty is high, that you will ignore this recommendation and you will points to the&lt;/P&gt;&lt;P&gt;'Use FOR ALL ENTRIES' recommendations' ... but then I can not help you.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Siegfried&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 04 Dec 2008 09:06:54 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/rewrite-sql-query-to-improve-performance/m-p/4832748#M1130621</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-12-04T09:06:54Z</dc:date>
    </item>
    <item>
      <title>Re: Rewrite SQL query to improve performance</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/rewrite-sql-query-to-improve-performance/m-p/4832749#M1130622</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;really try it out what Siegfried mentioned. Without an appropriate SQL monitoring you only shot in the dark.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;A class="jive_macro jive_macro_blogpost" href="https://community.sap.com/" __jive_macro_name="blogpost" modifiedtitle="true" __default_attr="44587"&gt;&lt;/A&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;It's explained easy &lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;gives you a lot of information back&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;makes you richer (your boss will rise your salary when you deliver the data in no time)&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;bye&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;yk&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 04 Dec 2008 09:11:35 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/rewrite-sql-query-to-improve-performance/m-p/4832749#M1130622</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-12-04T09:11:35Z</dc:date>
    </item>
    <item>
      <title>Re: Rewrite SQL query to improve performance</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/rewrite-sql-query-to-improve-performance/m-p/4832750#M1130623</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;you can lead a horse to the water, but you can't make him drink ...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;bye&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;yk&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 04 Dec 2008 09:13:53 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/rewrite-sql-query-to-improve-performance/m-p/4832750#M1130623</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-12-04T09:13:53Z</dc:date>
    </item>
    <item>
      <title>Re: Rewrite SQL query to improve performance</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/rewrite-sql-query-to-improve-performance/m-p/4832751#M1130624</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;I am definitely not ignoring your suggestion .But could you please explain why 'For all Entries' won't be of help in this case?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 04 Dec 2008 11:04:23 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/rewrite-sql-query-to-improve-performance/m-p/4832751#M1130624</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-12-04T11:04:23Z</dc:date>
    </item>
    <item>
      <title>Re: Rewrite SQL query to improve performance</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/rewrite-sql-query-to-improve-performance/m-p/4832752#M1130625</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It is not suggestable to use join on more than 2 tables. Try to break the join into 2 select stmts.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Also INTO CORRESPONDING FIELDS, is a performance constraint, unless and until it is a mandatory requrement never use it. try to maintain your internal table in the order of the data retreival (Select stmt), and then move the data.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This might help your performance issues to some extent.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Also make sure while use for all entries, never for get to use if not initial[] stmt on the table that is being used for all entries. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;eg:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if not x[] is initail.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;select a b c &lt;/P&gt;&lt;P&gt;   from y &lt;/P&gt;&lt;P&gt;for all entries in x&lt;/P&gt;&lt;P&gt;where ......&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Endif.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Not using the if not initial may cause application break down if the table is initial in any case, so it is always advisable to use the stmt.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 05 Dec 2008 18:51:14 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/rewrite-sql-query-to-improve-performance/m-p/4832752#M1130625</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-12-05T18:51:14Z</dc:date>
    </item>
    <item>
      <title>Re: Rewrite SQL query to improve performance</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/rewrite-sql-query-to-improve-performance/m-p/4832753#M1130626</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&amp;gt; It is not suggestable to use join on more than 2 tables.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;that is simply nonsense!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
WHERE a~vkorg IN so_vkorg
AND a~vtweg IN so_vtweg
AND a~vkbur IN so_vkbur
AND a~auart IN so_auart
AND a~vbeln IN so_vbeln
AND b~abgru IN so_abgru
AND c~faksk IN so_faksk
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;First you must understand the idea behind ranges.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Your statements will never use all ranges together, that nearly never the case =&amp;gt; there are different&lt;/P&gt;&lt;P&gt;combinations, some are well supported by indexes, some probably not.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;FOR ALL ENTRIES need also indexes, they can not automatically solve your problem. A well-defined&lt;/P&gt;&lt;P&gt;join is faster than a FAE even for more than 2 tables.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Siegfried&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 08 Dec 2008 07:43:47 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/rewrite-sql-query-to-improve-performance/m-p/4832753#M1130626</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-12-08T07:43:47Z</dc:date>
    </item>
    <item>
      <title>Re: Rewrite SQL query to improve performance</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/rewrite-sql-query-to-improve-performance/m-p/4832754#M1130627</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Raghava,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;sorry - a big NO. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The FAE myth spreads around here for a long time. It can NEVER be a replacement for a join.&lt;/P&gt;&lt;P&gt;Joins will provide a way for the database to know in advance about WHAT data to look for.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you break it up in several statements it can't provide an efficient execution plan because &lt;/P&gt;&lt;P&gt;you hold back important information (i.e. the reference tables to retrieve data from).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The key with joins is efficient indexing and knowing the data model.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if you can't locate the data in another table you may use FAE - but you must be aware of it's restrictions:&lt;/P&gt;&lt;P&gt;see: SAP Note 48230 - Parameters for the SELECT ... FOR ALL ENTRIES statement&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Bye&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;yk&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 08 Dec 2008 14:09:22 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/rewrite-sql-query-to-improve-performance/m-p/4832754#M1130627</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-12-08T14:09:22Z</dc:date>
    </item>
  </channel>
</rss>

