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 > Performance of two sql files

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-08-09, 03:43
shahnazurs shahnazurs is offline
Registered User
 
Join Date: May 2005
Posts: 25
Performance of two sql files

hi,

I used the following statement in two different files and tries to execute two SQL files, which one would be faster and why?

1 ->

Code:
merge into abc.emp1 a
using abc.emp b
on
(
	a.empno=b.empno
)
when matched then
update set 
	ename=b.ename,
	sal=b.sal
when not matched then
	insert (empno,ename,sal)
	values(b.empno,b.ename,b.sal);
2->

merge into abc.emp1 a
using abc.emp b
on
(
a.empno=b.empno
)
when matched then
update set
ename=b.ename,
sal=b.sal;

insert into abc.emp1 a
select empno,ename,sal
from
abc.emp
where not exists(select 1 from abc.emp where empno=a.empno);
Reply With Quote
  #2 (permalink)  
Old 07-08-09, 04:41
dr_te_z dr_te_z is offline
Registered User
 
Join Date: Jan 2009
Location: Zoetermeer, Holland
Posts: 555
1- you make 1 trip to the database engine
2- you make 2 trips to the database engine

That alone makes me vote for #1
Reply With Quote
  #3 (permalink)  
Old 07-08-09, 07:38
shahnazurs shahnazurs is offline
Registered User
 
Join Date: May 2005
Posts: 25
Thanks buddy.

Any other suggestions?
Reply With Quote
  #4 (permalink)  
Old 07-08-09, 07:40
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
Quote:
Originally Posted by shahnazurs
hi,

I used the following statement in two different files and tries to execute two SQL files, which one would be faster and why?
Why don't you run a test and tell us? As to why, this question is easily answered by observing the statement execution plans.

PS. Please don't call me "buddy".
Reply With Quote
  #5 (permalink)  
Old 07-08-09, 08:25
shahnazurs shahnazurs is offline
Registered User
 
Join Date: May 2005
Posts: 25
Hi,

I would have said easily if it is Oracle DB i.e. taking execution plan or trace. Since I am novice in DB2 database,I feel difficult in doing that. pls. don't mind about calling "buddy"

Thanks,
Shahnaz.
Reply With Quote
  #6 (permalink)  
Old 07-08-09, 09:34
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
Quote:
Originally Posted by shahnazurs
Hi,

I would have said easily if it is Oracle DB i.e. taking execution plan or trace. Since I am novice in DB2 database,I feel difficult in doing that.
Oracle and DB2 are not that different (finally) when it comes to the query optimization. The easiest way to see a query execution plan is to use the db2expln utility, which is described in the manuals.

Quote:
Originally Posted by shahnazurs
pls. don't mind about calling "buddy"
Actually, I do mind when strangers call me "buddy". I hope it's not too much of a trouble for you.
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