<?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: Performance issue when using select count on large tables in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/performance-issue-when-using-select-count-on-large-tables/m-p/6127198#M1364779</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Your issue has nothing to do with the COUNT(*), I see the usual 2 problems:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;There is a nested loop with 2 full tables no conditions, how many lines are in each of the two internal tables,&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;  do you really need all combinations?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;Most important, I don't think that there are proper indices for your select statement, i.e. the join. Therefore it is slow.&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;=&amp;gt; Combine the two internal tables into one, which really holds the combinations you need.&lt;/P&gt;&lt;P&gt;=&amp;gt; Do the SELECT with an FOR ALL ENTRIES&lt;/P&gt;&lt;P&gt;=&amp;gt; Most important, take care about the indices, either you must create indices or if your application is one time execution&lt;/P&gt;&lt;P&gt;     you must create a batch program which will need its time.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Siegfried&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 23 Sep 2009 07:53:17 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2009-09-23T07:53:17Z</dc:date>
    <item>
      <title>Performance issue when using select count on large tables</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/performance-issue-when-using-select-count-on-large-tables/m-p/6127193#M1364774</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Experts,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have a requirement where i need to get count of data  from a database table.Later on i need to display the count in ALV format.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;As per my requirement, I have to use this select count inside a nested loops.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Below is the count snippet:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;LOOP at systems assigning &amp;lt;fs_sc_systems&amp;gt;.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;LOOP at date assigning &amp;lt;fs_sc_date&amp;gt;.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SELECT COUNT( DISTINCT crmd_orderadm_i~header )&lt;/P&gt;&lt;P&gt;   FROM crmd_orderadm_i&lt;/P&gt;&lt;P&gt;   INNER JOIN bbp_pdigp&lt;/P&gt;&lt;P&gt;       ON crmd_orderadm_i&lt;SUB&gt;client EQ bbp_pdigp&lt;/SUB&gt;client               "MANDT is referred as client&lt;/P&gt;&lt;P&gt;     AND crmd_orderadm_i&lt;SUB&gt;guid  EQ bbp_pdigp&lt;/SUB&gt;guid&lt;/P&gt;&lt;P&gt;     INTO w_sc_count&lt;/P&gt;&lt;P&gt; WHERE crmd_orderadm_i~created_at BETWEEN &amp;lt;fs_sc_date&amp;gt;-start_timestamp&lt;/P&gt;&lt;P&gt;     AND &amp;lt;fs_sc_date&amp;gt;-end_timestamp&lt;/P&gt;&lt;P&gt;     AND bbp_pdigp~zz_scsys   EQ &amp;lt;fs_sc_systems&amp;gt;-sys_name.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;endloop.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;endloop.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In the above code snippet,&lt;/P&gt;&lt;P&gt;&amp;lt;fs_sc_systems&amp;gt;-sys_name is having the system name,&lt;/P&gt;&lt;P&gt;&amp;lt;fs_sc_date&amp;gt;-start_timestamp is having the start date of month&lt;/P&gt;&lt;P&gt;and &amp;lt;fs_sc_date&amp;gt;-end_timestamp is the end date of month.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Also the data in tables crmd_orderadm_i and bbp_pdigp is very large and it increases every day.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now,the above select query is taking a lot of time to give the count due to which i am facing performance issues.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Can any one pls help me out to optimize this code.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Suman&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 12 Sep 2009 10:26:26 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/performance-issue-when-using-select-count-on-large-tables/m-p/6127193#M1364774</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-09-12T10:26:26Z</dc:date>
    </item>
    <item>
      <title>Re: Performance issue when using select count on large tables</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/performance-issue-when-using-select-count-on-large-tables/m-p/6127194#M1364775</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Try only one select (remove the loops), and use a cursor so that to read by package into a first internal table with the system, timestamp and the guid. For each package, collect this internal table into another internal table made of system, time interval, count.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 13 Sep 2009 20:18:00 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/performance-issue-when-using-select-count-on-large-tables/m-p/6127194#M1364775</guid>
      <dc:creator>Sandra_Rossi</dc:creator>
      <dc:date>2009-09-13T20:18:00Z</dc:date>
    </item>
    <item>
      <title>Re: Performance issue when using select count on large tables</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/performance-issue-when-using-select-count-on-large-tables/m-p/6127195#M1364776</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Suman, &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Build you logic in such a way that you select all the records from the database table in one go into an internal table.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;And then you read this internal table to get the count of desired records.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This is surely give improvement in performance.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 14 Sep 2009 03:38:46 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/performance-issue-when-using-select-count-on-large-tables/m-p/6127195#M1364776</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-09-14T03:38:46Z</dc:date>
    </item>
    <item>
      <title>Re: Performance issue when using select count on large tables</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/performance-issue-when-using-select-count-on-large-tables/m-p/6127196#M1364777</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;use for all entries on one table on which you are looping and for that date you can create  a range.&lt;/P&gt;&lt;P&gt;remove those two loops.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;and its better not to keep nonkey elements at all in the where conditions. because for each nonkey element it will any ways hit each and every lines of database table. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;fetch the records and filter them in a loop.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 14 Sep 2009 04:53:27 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/performance-issue-when-using-select-count-on-large-tables/m-p/6127196#M1364777</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-09-14T04:53:27Z</dc:date>
    </item>
    <item>
      <title>Re: Performance issue when using select count on large tables</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/performance-issue-when-using-select-count-on-large-tables/m-p/6127197#M1364778</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Choudhary Suman ,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Try this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SELECT crmd_orderadm_i~header&lt;/P&gt;&lt;P&gt;  INTO it_header                 " interna table&lt;/P&gt;&lt;P&gt;  FROM crmd_orderadm_i&lt;/P&gt;&lt;P&gt; INNER JOIN bbp_pdigp&lt;/P&gt;&lt;P&gt;    ON crmd_orderadm_i&lt;SUB&gt;client EQ bbp_pdigp&lt;/SUB&gt;client &lt;/P&gt;&lt;P&gt;   AND crmd_orderadm_i&lt;SUB&gt;guid   EQ bbp_pdigp&lt;/SUB&gt;guid&lt;/P&gt;&lt;P&gt;   FOR ALL ENTRIES IN date&lt;/P&gt;&lt;P&gt; WHERE crmd_orderadm_i~created_at BETWEEN date-start_timestamp&lt;/P&gt;&lt;P&gt;                                      AND date-end_timestamp&lt;/P&gt;&lt;P&gt;   AND bbp_pdigp~zz_scsys EQ date-sys_name.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;    SORT it_header BY header.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;    DELETE ADJACENT DUPLICATES FROM it_header&lt;/P&gt;&lt;P&gt;    COMPARING header.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;    describe table it_header lines v_lines. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope this information is help to you.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;José&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 22 Sep 2009 21:38:43 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/performance-issue-when-using-select-count-on-large-tables/m-p/6127197#M1364778</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-09-22T21:38:43Z</dc:date>
    </item>
    <item>
      <title>Re: Performance issue when using select count on large tables</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/performance-issue-when-using-select-count-on-large-tables/m-p/6127198#M1364779</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Your issue has nothing to do with the COUNT(*), I see the usual 2 problems:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;There is a nested loop with 2 full tables no conditions, how many lines are in each of the two internal tables,&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;  do you really need all combinations?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;Most important, I don't think that there are proper indices for your select statement, i.e. the join. Therefore it is slow.&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;=&amp;gt; Combine the two internal tables into one, which really holds the combinations you need.&lt;/P&gt;&lt;P&gt;=&amp;gt; Do the SELECT with an FOR ALL ENTRIES&lt;/P&gt;&lt;P&gt;=&amp;gt; Most important, take care about the indices, either you must create indices or if your application is one time execution&lt;/P&gt;&lt;P&gt;     you must create a batch program which will need its time.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Siegfried&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 23 Sep 2009 07:53:17 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/performance-issue-when-using-select-count-on-large-tables/m-p/6127198#M1364779</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-09-23T07:53:17Z</dc:date>
    </item>
    <item>
      <title>Re: Performance issue when using select count on large tables</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/performance-issue-when-using-select-count-on-large-tables/m-p/6127199#M1364780</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello All,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I cant merge the 2 loops into one.Also when i checked in debug mode select  count for taking a bit time.Anyways,, now i have sceduled my report  for background running.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for all ur response.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Suman&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 23 Sep 2009 09:22:44 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/performance-issue-when-using-select-count-on-large-tables/m-p/6127199#M1364780</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-09-23T09:22:44Z</dc:date>
    </item>
    <item>
      <title>Re: Performance issue when using select count on large tables</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/performance-issue-when-using-select-count-on-large-tables/m-p/6127200#M1364781</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;if you really need all combinations you could still try to use FAE (FOR ALL ENTRIES) in order to reduce the number of database calls. And checking the execution plan for tuning potential (with and without FAE) is a must.&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>Wed, 23 Sep 2009 10:30:33 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/performance-issue-when-using-select-count-on-large-tables/m-p/6127200#M1364781</guid>
      <dc:creator>HermannGahm</dc:creator>
      <dc:date>2009-09-23T10:30:33Z</dc:date>
    </item>
    <item>
      <title>Re: Performance issue when using select count on large tables</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/performance-issue-when-using-select-count-on-large-tables/m-p/6127201#M1364782</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Suman,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you can perform a SELECT inside two LOOP's you can use the two LOOP's to fill a new internal table with the fields for date and system. After that use this internal table as parameter of FOR ALL ENTRIES on suggested SELECT.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Another issue on your SELECT is index, there's no standard index on table crmd_orderadm_i for field created_at, you need to create a Z index for it go faster. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The best way to check this table/index access is use ST05. There's a explanation about how use it on the stick on this forum.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards, Fernando Da Ros&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 24 Sep 2009 05:47:46 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/performance-issue-when-using-select-count-on-large-tables/m-p/6127201#M1364782</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-09-24T05:47:46Z</dc:date>
    </item>
    <item>
      <title>Re: Performance issue when using select count on large tables</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/performance-issue-when-using-select-count-on-large-tables/m-p/6127202#M1364783</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&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; Thanks for all ur response.&lt;/P&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;If your question is answered, please assign po(i)nts to the helpful answers and mark this as closed.&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, 24 Sep 2009 13:05:02 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/performance-issue-when-using-select-count-on-large-tables/m-p/6127202#M1364783</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-09-24T13:05:02Z</dc:date>
    </item>
  </channel>
</rss>

