If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > SQL Query Question - Please Help : )

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-23-03, 23:19
dbfo04 dbfo04 is offline
Registered User
 
Join Date: Nov 2003
Posts: 1
Angry SQL Query Question - Please Help : )

Hi,

I am working on a query like the following:

select a.f1,b.f2,c.f3
from t1 as a
join t2 as b
on a.id=b.id
left join t3 as c
on b.id2=c.id2
where a.type in ('a','b','c');

someone told me that it is not efficient because all rows in table a will be readed before the where statement is used to narrow down the population. Is this true? If so, if I change the query as the following, will the performance be improved?

select a.f1,b.f2,c.f3
from t1 as a
join t2 as b
on a.id=b.id
and a.type in ('a','b','c');
left join t3 as c
on b.id2=c.id2
;

Thanks for your help : )
Reply With Quote
  #2 (permalink)  
Old 11-24-03, 01:18
grofaty grofaty is offline
Registered User
 
Join Date: Jan 2003
Posts: 1,570
Hi,

According to my knowleadge the SQL's are the same. Ther DB2 rewriter will most probably rewrite the SQL. Try using SQL explain to see the access path or use the visual explain from Command Center.

You can also read the following thread about Performance.

Hope this helps,
Grofaty
Reply With Quote
  #3 (permalink)  
Old 11-24-03, 03:46
sathyaram_s sathyaram_s is offline
Super Moderator
 
Join Date: Aug 2001
Location: UK
Posts: 4,534
Your explain will also give you the Optimized SQL ... This will help you to understand how DB2 has 'rewritten' your statement

Cheers
Sathyaram
__________________
Visit the new-look IDUG Website , register to gain access to the excellent content.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On