<?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: Better performance while joining tables in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/better-performance-while-joining-tables/m-p/4011599#M958475</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;First is the header table and then the line item table.&lt;/P&gt;&lt;P&gt;All the fields in the where cond. should be in the same order of the primary keys .&lt;/P&gt;&lt;P&gt;If you give all the necessary fields in the select stmt in the same order as in the table , it will be fast. Better not to give into corresponding fields of table.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Avoid select *.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Subramanian&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 23 Jun 2008 05:48:25 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2008-06-23T05:48:25Z</dc:date>
    <item>
      <title>Better performance while joining tables</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/better-performance-while-joining-tables/m-p/4011598#M958474</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Dear friends&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When we join 2 tables, say EKKO &amp;amp; EKPO in select query what is the order of fields and the order of where conditions to be given  for getting better performance. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is it all fields from header table first and then from item table??&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Sathar&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 23 Jun 2008 05:43:05 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/better-performance-while-joining-tables/m-p/4011598#M958474</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-06-23T05:43:05Z</dc:date>
    </item>
    <item>
      <title>Re: Better performance while joining tables</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/better-performance-while-joining-tables/m-p/4011599#M958475</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;First is the header table and then the line item table.&lt;/P&gt;&lt;P&gt;All the fields in the where cond. should be in the same order of the primary keys .&lt;/P&gt;&lt;P&gt;If you give all the necessary fields in the select stmt in the same order as in the table , it will be fast. Better not to give into corresponding fields of table.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Avoid select *.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Subramanian&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 23 Jun 2008 05:48:25 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/better-performance-while-joining-tables/m-p/4011599#M958475</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-06-23T05:48:25Z</dc:date>
    </item>
    <item>
      <title>Re: Better performance while joining tables</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/better-performance-while-joining-tables/m-p/4011600#M958476</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;For better performance use syntax For All Entries.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;First select data from EKKO then from EKPO for all entries in Itab 1.&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, 23 Jun 2008 05:48:50 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/better-performance-while-joining-tables/m-p/4011600#M958476</guid>
      <dc:creator>nikhil_chitre</dc:creator>
      <dc:date>2008-06-23T05:48:50Z</dc:date>
    </item>
    <item>
      <title>Re: Better performance while joining tables</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/better-performance-while-joining-tables/m-p/4011601#M958477</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Sathar, &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if you join two tables in SQL, there is no prefered order in fields or in predicates in the WHERE clause. There is also no need for an order in the FROM clause. This is the theory and the supported database getting better and better in realizing this. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If we now look to your example EKKO &amp;amp; EKPO, usually you'll search for some header data first and want to select the line items in addition. But may be you have a more restrictive predicate on the line item table and there is a suitable index on it, then the database optimizer would use this table first and then read the header lines for the line items found. What I would like to tell you is, all depends on the WHERE clause. Which table the predicates in WHERE clause filters less lines, the more likely it will be used as driving table (this is the table read first by the database). In your example it is very likely that EKKO will be the driving table because there is at least one line in EKKO for each line in EKPO but more the other way around. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For best performance you should choose the join condition wright: &lt;/P&gt;&lt;P&gt;FROM EKKO INNER JOIN EKPO &lt;/P&gt;&lt;P&gt;   ON EKKO&lt;SUB&gt;EBELN = EKPO&lt;/SUB&gt;EBELN &lt;/P&gt;&lt;P&gt;AND EKKO&lt;SUB&gt;MANDT = EKPO&lt;/SUB&gt;MANDT (if you want to be very friendly to the optimizer) &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Then choose only the fields you really need in the selection list and specify the where clause to select least possible number of rows. You could check if there is a suitable index for performance. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Best regards &lt;/P&gt;&lt;P&gt;Ralph&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 23 Jun 2008 08:09:46 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/better-performance-while-joining-tables/m-p/4011601#M958477</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-06-23T08:09:46Z</dc:date>
    </item>
    <item>
      <title>Re: Better performance while joining tables</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/better-performance-while-joining-tables/m-p/4011602#M958478</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;There are some wrong informations here, which need to be corrected:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;"First is the header table and then the line item table."&lt;/P&gt;&lt;P&gt;==&amp;gt; It does not matter&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;"All the fields in the where cond. should be in the same order of the primary keys ."&lt;/P&gt;&lt;P&gt;==&amp;gt; This is again not true...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;"For better performance use syntax For All Entries."&lt;/P&gt;&lt;P&gt;==&amp;gt; I've read this here on SDN 1000th times, but it is just simply not true or at least not that simple. You always have to give a try, but I believe that in this case (EKKO and EKPO) the JOIN will be faster.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;"For best performance you should choose the join condition wright: &lt;/P&gt;&lt;P&gt;FROM EKKO INNER JOIN EKPO &lt;/P&gt;&lt;P&gt;ON EKKO&lt;SUB&gt;EBELN = EKPO&lt;/SUB&gt;EBELN &lt;/P&gt;&lt;P&gt;AND EKKO&lt;SUB&gt;MANDT = EKPO&lt;/SUB&gt;MANDT (if you want to be very friendly to the optimizer)"&lt;/P&gt;&lt;P&gt;==&amp;gt; The client field (MANDT) can be forgotten, you don't have to specify at all.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;"Then choose only the fields you really need in the selection list and specify the where clause to select least possible number of rows. You could check if there is a suitable index for performance."&lt;/P&gt;&lt;P&gt;==&amp;gt; No index will be helpful by JOINs &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;hope this helps&lt;/P&gt;&lt;P&gt;ec&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 23 Jun 2008 08:22:14 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/better-performance-while-joining-tables/m-p/4011602#M958478</guid>
      <dc:creator>JozsefSzikszai</dc:creator>
      <dc:date>2008-06-23T08:22:14Z</dc:date>
    </item>
    <item>
      <title>Re: Better performance while joining tables</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/better-performance-while-joining-tables/m-p/4011603#M958479</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Eric,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;good points at the beginning, but your statements about my posting requires an answer.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I wrote that the client filed is not necessary, but in some strange situations the optimizer has chosen the wrong path because it does not get this additional information. This happens probably not in such an easy join but it happend on one of my systems. But in principle you're wright, it is not necessary.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Your other statement is wrong. Indexes matter for joins. You can verify this easily be checking the execution plan. If you mean secondary indexes my the term index, then you're wright, because in the example the primary key index will be used.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Ralph&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 23 Jun 2008 19:33:30 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/better-performance-while-joining-tables/m-p/4011603#M958479</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-06-23T19:33:30Z</dc:date>
    </item>
  </channel>
</rss>

