 




<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: DB2/400 SQL Sub Query Performance?</title>
	<atom:link href="http://itknowledgeexchange.techtarget.com/itanswers/db2400-sql-sub-query-performance/feed/" rel="self" type="application/rss+xml" />
	<link>http://itknowledgeexchange.techtarget.com/itanswers/db2400-sql-sub-query-performance/</link>
	<description></description>
	<lastBuildDate>Thu, 23 May 2013 01:41:43 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
	<item>
		<title>By: bigkat</title>
		<link>http://itknowledgeexchange.techtarget.com/itanswers/db2400-sql-sub-query-performance/#comment-48231</link>
		<dc:creator>bigkat</dc:creator>
		<pubDate>Thu, 21 Oct 2004 11:59:38 +0000</pubDate>
		<guid isPermaLink="false">#comment-48231</guid>
		<description><![CDATA[SQL on the iSeries seems to have a couple of quirks from other platforms.   It seems that in a statement using &quot;where EVENT in (Select EVENT from INVEHH...&quot; syntax, the &quot;in&quot; select is run for EVERY record in the outer statement.

Try using an inner join syntax.  I&#039;ve found it to help most of the time!

select EVENT, INUMBR, ISTORE, EVHYY, EVHMM, EVHDD 
from INVEHD as a inner join (Select distinct EVENT from INVEHH where (EVHYY*10000 + EVHMM*100 + EVHDD)= 20040617) as b on a.EVENT = b.event

even better is to use EVHYY = 2004 and EVHMM = 06 and EVHDD = 17 instead of (EVHYY*10000 + EVHMM*100 + EVHDD)= 20040617 because SQL can make use of a logical over the date fields if they exist

if you can say that there can NEVER be duplicate EVENTs selected from the INVEHH file, you can eliminate the distinct from the statement.  Not knowing the data relationships for sure I added the distinct just in case.]]></description>
		<content:encoded><![CDATA[<p>SQL on the iSeries seems to have a couple of quirks from other platforms.   It seems that in a statement using &#8220;where EVENT in (Select EVENT from INVEHH&#8230;&#8221; syntax, the &#8220;in&#8221; select is run for EVERY record in the outer statement.</p>
<p>Try using an inner join syntax.  I&#8217;ve found it to help most of the time!</p>
<p>select EVENT, INUMBR, ISTORE, EVHYY, EVHMM, EVHDD<br />
from INVEHD as a inner join (Select distinct EVENT from INVEHH where (EVHYY*10000 + EVHMM*100 + EVHDD)= 20040617) as b on a.EVENT = b.event</p>
<p>even better is to use EVHYY = 2004 and EVHMM = 06 and EVHDD = 17 instead of (EVHYY*10000 + EVHMM*100 + EVHDD)= 20040617 because SQL can make use of a logical over the date fields if they exist</p>
<p>if you can say that there can NEVER be duplicate EVENTs selected from the INVEHH file, you can eliminate the distinct from the statement.  Not knowing the data relationships for sure I added the distinct just in case.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: apothen</title>
		<link>http://itknowledgeexchange.techtarget.com/itanswers/db2400-sql-sub-query-performance/#comment-48232</link>
		<dc:creator>apothen</dc:creator>
		<pubDate>Thu, 21 Oct 2004 10:21:17 +0000</pubDate>
		<guid isPermaLink="false">#comment-48232</guid>
		<description><![CDATA[The problem is not the subquery, that&#039;s running over a table that has only about 1000 records.  My question really is about how DB2/400 optimizes the query.

This is how I think the query optimizer should do:

Step 1) Run the subquery over the table with 500 records - should run really fast.
Step 2) Now run the main query using the result set - The table is indeed indexed by the field (element) in the where clouse.

What seems to be happenning is:

DB2/400 runs the subquery for each one of the records in the big table with 22 million records.

I know in SQL Server and Oracle, we can look at the query execution path and make changes to it, if RDBMS did not pick the best route.

So my question really is, is there any such facility in DB2/400? or Does DB2/400 expect the queries to be structured in some other fashion that is specific to the platform?

]]></description>
		<content:encoded><![CDATA[<p>The problem is not the subquery, that&#8217;s running over a table that has only about 1000 records.  My question really is about how DB2/400 optimizes the query.</p>
<p>This is how I think the query optimizer should do:</p>
<p>Step 1) Run the subquery over the table with 500 records &#8211; should run really fast.<br />
Step 2) Now run the main query using the result set &#8211; The table is indeed indexed by the field (element) in the where clouse.</p>
<p>What seems to be happenning is:</p>
<p>DB2/400 runs the subquery for each one of the records in the big table with 22 million records.</p>
<p>I know in SQL Server and Oracle, we can look at the query execution path and make changes to it, if RDBMS did not pick the best route.</p>
<p>So my question really is, is there any such facility in DB2/400? or Does DB2/400 expect the queries to be structured in some other fashion that is specific to the platform?</p>
]]></content:encoded>
	</item>
</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Page Caching using memcached
Database Caching 3/10 queries in 0.038 seconds using memcached
Object Caching 281/287 objects using memcached

Served from: itknowledgeexchange.techtarget.com @ 2013-05-23 01:42:37 -->