<?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: Select query getting too slow. in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-query-getting-too-slow/m-p/5415912#M1243443</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Performance is a biit complicate, you must be able to read and to understand,&lt;/P&gt;&lt;P&gt;just looking at patterns, 2 or 3 joins will not help.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I think here the subselect kills the performance. Subselects are often very good, but&lt;/P&gt;&lt;P&gt;here it is not done once, but for every customer number,  t1~kunnr&lt;/P&gt;&lt;P&gt;And it is even done when s_chg_dt is empty, I would assume that this is simply a bug!!!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Try the following, I can not improve the porblem in one step without a system:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
 IF  ( s_chg_dt IS INITIAL ).

   SELECT t1~kunnr t2~name1 t2~name2 t2~name3 t2~sort1
            INTO TABLE i_cust_details
           FROM kna1 AS t1
            INNER JOIN adrc AS t2
           ON t2~addrnumber = t1~adrnr
           INNER JOIN cdhdr AS t3
          ON t3~objectid = t1~kunnr
          WHERE t1~kunnr IN s_kunnr                        " Customer
                AND t1~erdat IN s_crt_dt                 " Creation date
                AND t3~objectclas = wc_objclass
                AND t1~ktokd = ZACT1.

ELSE.

    SELECT objectclas objectid MAX( changenr ) as changenr
                  INTO TABLE .... itab ...                  
                  FROM cdhdr AS t4
                  WHERE t4~objectclas = wc_objclass
                  AND t4~objectid   = t1~kunnr
                  AND t4~udate     IN s_chg_dt.

     SELECT t1~kunnr t2~name1 t2~name2 t2~name3 t2~sort1
                   INTO TABLE i_cust_details
                   FROM kna1 AS t1
                   INNER JOIN adrc AS t2
                   ON t2~addrnumber = t1~adrnr
                   INNER JOIN cdhdr AS t3
                   ON t3~objectid = t1~kunnr
                   FOR ALL EMTRIES IN itab
                   WHERE t1~kunnr = itab-object
                   AND      t1~erdat IN s_crt_dt           " Creation date
                   AND t3~changenr = itab-changenr
                   AND t3~objectclas = wc_objclass
                   AND t1~ktokd = ZACT1.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Customer : S_KUNNR   and Create date : S_CRT_DT   are mandatory&lt;/P&gt;&lt;P&gt;only Change Date : S_CHG_DT is optional.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If any combination is allowed, then it becomes more complicated.&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, 26 Mar 2009 13:33:54 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2009-03-26T13:33:54Z</dc:date>
    <item>
      <title>Select query getting too slow.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-query-getting-too-slow/m-p/5415905#M1243436</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Friends,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have a performance tunning problem.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have select options like,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Customer : S_KUNNR&lt;/P&gt;&lt;P&gt;Create date : S_CRT_DT&lt;/P&gt;&lt;P&gt;Change Date : S_CHG_DT&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;for this i am executing following select query.&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
* Get the customer details.
  SELECT t1~kunnr t2~name1 t2~name2 t2~name3 t2~sort1
      INTO TABLE i_cust_details
      FROM kna1 AS t1
      INNER JOIN adrc AS t2
        ON t2~addrnumber = t1~adrnr
      INNER JOIN cdhdr AS t3
        ON t3~objectid = t1~kunnr
    WHERE t1~kunnr IN s_kunnr            " Customer
      AND t1~erdat IN s_crt_dt           " Creation date
*     Following sub query for the most recent changed date.
      AND t3~changenr = ( SELECT MAX( changenr )
                               FROM cdhdr AS t4
                            WHERE t4~objectclas = wc_objclass
                              AND t4~objectid   = t1~kunnr
                              AND t4~udate     IN s_chg_dt )

      AND t3~objectclas = wc_objclass
      AND t1~ktokd = ZACT1.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;but it takes mauch time.&lt;/P&gt;&lt;P&gt;how can i solve this?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 25 Mar 2009 11:39:02 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-query-getting-too-slow/m-p/5415905#M1243436</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-03-25T11:39:02Z</dc:date>
    </item>
    <item>
      <title>Re: Select query getting too slow.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-query-getting-too-slow/m-p/5415906#M1243437</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Ronny,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The best option is what retrieves faster for you, the schedule of execution (hourly, daily, monthly) have you help you to choose the correct for your case.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Anyway, a index on field udate is probably mandatory for date/time acess.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;option 1: Read the pointers before read what changed.&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;SELECT DISTINCT objectid INTO TABLE tl_objects FROM cdhdr
WHERE objectclas = wc_objclass
  AND objectid   IN s_objectid   "Move the s_kunnr to s_objectid
  AND udate     IN s_chg_dt.

CHECK tl_objects[] IS NOT INITIAL.

* move the content tl_objects to a table with kunnr as key

SELECT t1~kunnr t2~name1 t2~name2 t2~name3 t2~sort1
INTO TABLE i_cust_details
FROM kna1 AS t1 INNER JOIN adrc AS t2
                ON t2~addrnumber = t1~adrnr
FOR ALL ENTRIES IN lt_changes
WHERE t1~kunnr EQ lt_changes-kunnr
  AND t1~erdat IN s_crt_dt
  AND t1~ktokd = ZACT1.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;option 2: You don't need cdhdr on inner join, try if this work:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;SELECT t1~kunnr t2~name1 t2~name2 t2~name3 t2~sort1
INTO TABLE i_cust_details
FROM kna1 AS t1 INNER JOIN adrc AS t2
                ON t2~addrnumber = t1~adrnr
WHERE t1~kunnr IN s_kunnr
  AND t1~erdat IN s_crt_dt
  AND t1~ktokd = ZACT1
  AND EXISTS ( SELECT * FROM FROM cdhdr AS t4
               WHERE t4~objectclas = wc_objclass
                 AND t4~objectid   = t1~kunnr
                 AND t4~udate     IN s_chg_dt )&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 25 Mar 2009 12:02:18 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-query-getting-too-slow/m-p/5415906#M1243437</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-03-25T12:02:18Z</dc:date>
    </item>
    <item>
      <title>Re: Select query getting too slow.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-query-getting-too-slow/m-p/5415907#M1243438</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Rony,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Try to use FOR ALL ENTRIES.... in place of INNER JOIN.it will improve performance of your query          certainly.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;By&lt;/P&gt;&lt;P&gt;Prasad GVK.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 25 Mar 2009 13:16:47 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-query-getting-too-slow/m-p/5415907#M1243438</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-03-25T13:16:47Z</dc:date>
    </item>
    <item>
      <title>Re: Select query getting too slow.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-query-getting-too-slow/m-p/5415908#M1243439</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;check the no of records in the debugging mode &lt;/P&gt;&lt;P&gt;i can suggest u that if the no records are small then use for all entries condition instead of inner join&lt;/P&gt;&lt;P&gt; i think it will give  better performance .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regds&lt;/P&gt;&lt;P&gt;Sachhi&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 25 Mar 2009 13:34:15 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-query-getting-too-slow/m-p/5415908#M1243439</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-03-25T13:34:15Z</dc:date>
    </item>
    <item>
      <title>Re: Select query getting too slow.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-query-getting-too-slow/m-p/5415909#M1243440</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;How many records are there typically in S_KUNNR?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Rob&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 25 Mar 2009 13:41:16 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-query-getting-too-slow/m-p/5415909#M1243440</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-03-25T13:41:16Z</dc:date>
    </item>
    <item>
      <title>Re: Select query getting too slow.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-query-getting-too-slow/m-p/5415910#M1243441</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;Do not join the table CDHDR, its a huge table, check the technical--&amp;gt;size category before joining table  . Avoid joining more than 2 tables. If you have to join use all the keys. Use for all entries.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Prashant.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 26 Mar 2009 07:44:50 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-query-getting-too-slow/m-p/5415910#M1243441</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-03-26T07:44:50Z</dc:date>
    </item>
    <item>
      <title>Re: Select query getting too slow.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-query-getting-too-slow/m-p/5415911#M1243442</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Prashant:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Please see the sticky at the top of the forum regarding JOINS and FOR ALL ENTRIES.&lt;/P&gt;&lt;P&gt;Can you show any SAP documentation that says not to JOIN more than two tables?&lt;/P&gt;&lt;P&gt;Can you show any SAP documentation that says not to JOIN large tables?&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, 26 Mar 2009 13:10:06 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-query-getting-too-slow/m-p/5415911#M1243442</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-03-26T13:10:06Z</dc:date>
    </item>
    <item>
      <title>Re: Select query getting too slow.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-query-getting-too-slow/m-p/5415912#M1243443</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Performance is a biit complicate, you must be able to read and to understand,&lt;/P&gt;&lt;P&gt;just looking at patterns, 2 or 3 joins will not help.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I think here the subselect kills the performance. Subselects are often very good, but&lt;/P&gt;&lt;P&gt;here it is not done once, but for every customer number,  t1~kunnr&lt;/P&gt;&lt;P&gt;And it is even done when s_chg_dt is empty, I would assume that this is simply a bug!!!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Try the following, I can not improve the porblem in one step without a system:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
 IF  ( s_chg_dt IS INITIAL ).

   SELECT t1~kunnr t2~name1 t2~name2 t2~name3 t2~sort1
            INTO TABLE i_cust_details
           FROM kna1 AS t1
            INNER JOIN adrc AS t2
           ON t2~addrnumber = t1~adrnr
           INNER JOIN cdhdr AS t3
          ON t3~objectid = t1~kunnr
          WHERE t1~kunnr IN s_kunnr                        " Customer
                AND t1~erdat IN s_crt_dt                 " Creation date
                AND t3~objectclas = wc_objclass
                AND t1~ktokd = ZACT1.

ELSE.

    SELECT objectclas objectid MAX( changenr ) as changenr
                  INTO TABLE .... itab ...                  
                  FROM cdhdr AS t4
                  WHERE t4~objectclas = wc_objclass
                  AND t4~objectid   = t1~kunnr
                  AND t4~udate     IN s_chg_dt.

     SELECT t1~kunnr t2~name1 t2~name2 t2~name3 t2~sort1
                   INTO TABLE i_cust_details
                   FROM kna1 AS t1
                   INNER JOIN adrc AS t2
                   ON t2~addrnumber = t1~adrnr
                   INNER JOIN cdhdr AS t3
                   ON t3~objectid = t1~kunnr
                   FOR ALL EMTRIES IN itab
                   WHERE t1~kunnr = itab-object
                   AND      t1~erdat IN s_crt_dt           " Creation date
                   AND t3~changenr = itab-changenr
                   AND t3~objectclas = wc_objclass
                   AND t1~ktokd = ZACT1.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Customer : S_KUNNR   and Create date : S_CRT_DT   are mandatory&lt;/P&gt;&lt;P&gt;only Change Date : S_CHG_DT is optional.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If any combination is allowed, then it becomes more complicated.&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, 26 Mar 2009 13:33:54 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-query-getting-too-slow/m-p/5415912#M1243443</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-03-26T13:33:54Z</dc:date>
    </item>
  </channel>
</rss>

