Unix Technical Forum

Delete vs. Merge

This is a discussion on Delete vs. Merge within the DB2 forums, part of the Database Server Software category; --> I need to delete some rows from a table. The rows to delete are uniquely identified in a second ...


Go Back   Unix Technical Forum > Database Server Software > DB2

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-27-2008, 04:13 AM
deebeetwo@yahoo.com
 
Posts: n/a
Default Delete vs. Merge

I need to delete some rows from a table. The rows to delete are
uniquely identified in a second table. I realize that I have two
options here:

1) DELETE FROM tableA WHERE ...

2) MERGE INTO tableA ... USING tableB ... ON .... WHEN MATCHED DELETE
....

I was wondering which of the two options would provide best performance
overall. I would welcome any suggestions.

Thanks!

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-27-2008, 04:13 AM
Serge Rielau
 
Posts: n/a
Default Re: Delete vs. Merge

deebeetwo@yahoo.com wrote:
> I need to delete some rows from a table. The rows to delete are
> uniquely identified in a second table. I realize that I have two
> options here:
>
> 1) DELETE FROM tableA WHERE ...
>
> 2) MERGE INTO tableA ... USING tableB ... ON .... WHEN MATCHED DELETE
> ...
>
> I was wondering which of the two options would provide best performance
> overall. I would welcome any suggestions.
>
> Thanks!
>

On average I would expect DELETE to be faster.
The reason is that MERGE has to raise an error if it tried to delete the
same row twice. This is extra work.
DELETE FROM T WHERE EXISTS(SELECT 1 FROM S WHERE T.c1 = S.c1)
Doesn't care wether S.c1 is unique.
If S.c1 and T.c1 are both keys MERGE may get up to the same speed
depedending on your fixpack.
MERGE can't be faster though :-)

Cheers
Serge
--
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 08:00 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com