<?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: Query optimization in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/query-optimization/m-p/871018#M49833</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Shehryar,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have tried with INTO TABLE instead of INTO CORRESPONDING... But its not giving me much support and same case for Order of where conditions.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;And i think one surprising news for you is, When i provide values in search-options then response time increases. It means that Query takes more time when any restriction is given in Search-option table.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Same query takes 15 sec. without any conditions in search option. But if i m specifying single value for Work center (S_ARBPL) then it takes 15 mins. for execution.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So now i m fetching all records without specifying search option conditions, and then i m deleting records from internal table based on the selection-option values.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So now i can get good performance result.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 31 Jan 2005 11:18:12 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2005-01-31T11:18:12Z</dc:date>
    <item>
      <title>Query optimization</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/query-optimization/m-p/871016#M49831</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I m facing a problem of Query optimization.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have used one query in report which takes too much time. Thhis query contains 4 inner join and one left join. All inner joins are in one-to-one relaionship. I am giving this query below.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SELECT catsdb~pernr&lt;/P&gt;&lt;P&gt;       catsdb~raufnr&lt;/P&gt;&lt;P&gt;       afru~budat&lt;/P&gt;&lt;P&gt;       catsdb~catshours&lt;/P&gt;&lt;P&gt;       afvc~vornr&lt;/P&gt;&lt;P&gt;       afih~equnr&lt;/P&gt;&lt;P&gt;       crhd~arbpl&lt;/P&gt;&lt;P&gt;       afvc~ltxa1&lt;/P&gt;&lt;P&gt;       catsdb~lstnr&lt;/P&gt;&lt;P&gt;       catsdb~sebeln&lt;/P&gt;&lt;P&gt;       catsdb~sebelp&lt;/P&gt;&lt;P&gt;       catsdb~belnr&lt;/P&gt;&lt;P&gt;       catsdb~workdate&lt;/P&gt;&lt;P&gt;  FROM catsdb INNER JOIN afih   ON catsdb&lt;SUB&gt;raufnr = afih&lt;/SUB&gt;aufnr&lt;/P&gt;&lt;P&gt;            INNER JOIN crhd   ON afih&lt;SUB&gt;gewrk = crhd&lt;/SUB&gt;objid&lt;/P&gt;&lt;P&gt;            INNER JOIN pa0315   ON catsdb&lt;SUB&gt;pernr = pa0315&lt;/SUB&gt;pernr&lt;/P&gt;&lt;P&gt;            INNER JOIN afvc ON catsdb&lt;SUB&gt;raufpl = afvc&lt;/SUB&gt;aufpl&lt;/P&gt;&lt;P&gt;                        AND catsdb&lt;SUB&gt;raplzl = afvc&lt;/SUB&gt;aplzl&lt;/P&gt;&lt;P&gt;            LEFT JOIN afru ON afru&lt;SUB&gt;aufnr = catsdb&lt;/SUB&gt;raufnr&lt;/P&gt;&lt;P&gt;                      AND afru&lt;SUB&gt;catsbelnr = catsdb&lt;/SUB&gt;belnr&lt;/P&gt;&lt;P&gt;  INTO CORRESPONDING FIELDS OF TABLE LT_AFRU&lt;/P&gt;&lt;P&gt; WHERE catsdb~pernr IN s_pernr&lt;/P&gt;&lt;P&gt;   AND catsdb~workdate IN s_wrkdat&lt;/P&gt;&lt;P&gt;   AND pa0315~lifnr IN s_lifnr&lt;/P&gt;&lt;P&gt;   AND afih~equnr &amp;lt;&amp;gt; ''&lt;/P&gt;&lt;P&gt;   AND crhd~objty = 'A'&lt;/P&gt;&lt;P&gt;   AND crhd~arbpl IN s_arbpl&lt;/P&gt;&lt;P&gt;   AND catsdb~belnr &amp;lt;&amp;gt; ''&lt;/P&gt;&lt;P&gt;   AND not catsdb~status in ('40','60').&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This query returns 343 records in our system.&lt;/P&gt;&lt;P&gt;Table record information is given below :&lt;/P&gt;&lt;P&gt;CATSDB : 432&lt;/P&gt;&lt;P&gt;AFRU : 573,142&lt;/P&gt;&lt;P&gt;AFIH : 859,363&lt;/P&gt;&lt;P&gt;PA0315 : 105&lt;/P&gt;&lt;P&gt;CRHD : 6237&lt;/P&gt;&lt;P&gt;AFVC : 1,040,925&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If anyone knows then Please give me alternate solution for this query faster than this query.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;thanks,&lt;/P&gt;&lt;P&gt;Bhavik&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 31 Jan 2005 08:14:01 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/query-optimization/m-p/871016#M49831</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2005-01-31T08:14:01Z</dc:date>
    </item>
    <item>
      <title>Re: Query optimization</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/query-optimization/m-p/871017#M49832</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;Take a look at &lt;A href="http://service.sap.com/performance" target="test_blank"&gt;http://service.sap.com/performance&lt;/A&gt; for tips on improving your program's performace.&lt;/P&gt;&lt;P&gt;A few tips though:&lt;/P&gt;&lt;P&gt;1. If possible, change the &amp;lt;b&amp;gt;INTO CORRESPONDING FIELDS OF TABLE LT_AFRU&amp;lt;/b&amp;gt; to &amp;lt;b&amp;gt;INTO TABLE LT_AFRU&amp;lt;/b&amp;gt;. &lt;/P&gt;&lt;P&gt;2. Check whether your select options contain at least 1 entry, otherwise the complete table will be scanned&lt;/P&gt;&lt;P&gt;3. Your WHERE clause needs a bit of rewriting. Try this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
WHERE catsdb~pernr IN s_pernr
AND catsdb~workdate IN s_wrkdat
AND catsdb~belnr &amp;lt;&amp;gt; '' "sequence changed, brought up
AND not catsdb~status in ('40','60') "sequence changed, brought up
AND pa0315~lifnr IN s_lifnr
AND afih~equnr &amp;lt;&amp;gt; ''
AND crhd~objty = 'A'
AND crhd~arbpl IN s_arbpl.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The order of search keys is very important. The DB Optimizer can choose an index only upto the last specified key in where clause. Try to put your selection criterion in the order with which keys are defind in Data Dictionary. See if you can further specifiy any key values to restrict selection.&lt;/P&gt;&lt;P&gt;4. Use ST05 to see whether indexes are being used. If not, see if it is suitable to create your own secondary indexes.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Do get back with feedback, if this helped. We can then further look into ways of improving the overall performance of the program as well as your current query.&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;Message was edited by: Shehryar Khan&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Message was edited by: Shehryar Khan&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 31 Jan 2005 10:22:41 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/query-optimization/m-p/871017#M49832</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2005-01-31T10:22:41Z</dc:date>
    </item>
    <item>
      <title>Re: Query optimization</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/query-optimization/m-p/871018#M49833</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Shehryar,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have tried with INTO TABLE instead of INTO CORRESPONDING... But its not giving me much support and same case for Order of where conditions.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;And i think one surprising news for you is, When i provide values in search-options then response time increases. It means that Query takes more time when any restriction is given in Search-option table.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Same query takes 15 sec. without any conditions in search option. But if i m specifying single value for Work center (S_ARBPL) then it takes 15 mins. for execution.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So now i m fetching all records without specifying search option conditions, and then i m deleting records from internal table based on the selection-option values.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So now i can get good performance result.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 31 Jan 2005 11:18:12 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/query-optimization/m-p/871018#M49833</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2005-01-31T11:18:12Z</dc:date>
    </item>
    <item>
      <title>Re: Query optimization</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/query-optimization/m-p/871019#M49834</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 INTO TABLE will not make a formidable difference. The difference will be minimal.&lt;/P&gt;&lt;P&gt;The order of where conditions is as good as one of the indexes is being used by the DB Optimizer to select values. If the where condition is still not allowing the optimizer to choose an index, order won't make much difference. As I said, use ST05 to see if indexes are being used by the optimizer. Additionally, check your program's execution through SE30 to identify bottlenecks, if any. &lt;/P&gt;&lt;P&gt;Fetching more records than required is not recommended. While it might work for your program for now, it will impact the overall performance of the SAP system in the long run. The performance might degrade as well when data volume increases in the database.&lt;/P&gt;&lt;P&gt;If your query uses indexes properly, your program will give you nearly linear dependecy upon the data volume.&lt;/P&gt;&lt;P&gt;Sometimes, rather than sending a single complex query to DB, breaking it into simpler, faster searches that use indexes turn out to be a good option as well. See if this works for you.&lt;/P&gt;&lt;P&gt;There is certainly no silver button for performance optimization. The data/transaction volume in your DEV system might not reflect the one in PRD. Only you know the current/expected situation. That's why I mentioned the recommended guidelines that work in most of the cases. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope this helps.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 31 Jan 2005 11:49:47 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/query-optimization/m-p/871019#M49834</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2005-01-31T11:49:47Z</dc:date>
    </item>
    <item>
      <title>Re: Query optimization</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/query-optimization/m-p/871020#M49835</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi. &lt;/P&gt;&lt;P&gt;Sometimes it can be useful to create a db view instead of a very complex query. Then the query is more clear to read (by programmer) and usually works much faster.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope this helps.&lt;/P&gt;&lt;P&gt;Lukasz&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 31 Jan 2005 12:05:05 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/query-optimization/m-p/871020#M49835</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2005-01-31T12:05:05Z</dc:date>
    </item>
  </channel>
</rss>

